Added test for large chunked gzipped content.
This commit is contained in:
parent
3162ccc299
commit
213d6e1fbd
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.proxy;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -34,7 +35,6 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
|
@ -72,7 +72,6 @@ import org.junit.Assert;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public class AsyncMiddleManServletTest
|
public class AsyncMiddleManServletTest
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(AsyncMiddleManServletTest.class);
|
private static final Logger LOG = Log.getLogger(AsyncMiddleManServletTest.class);
|
||||||
|
@ -617,6 +616,17 @@ public class AsyncMiddleManServletTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLargeChunkedBufferedDownstreamTransformation() throws Exception
|
public void testLargeChunkedBufferedDownstreamTransformation() throws Exception
|
||||||
|
{
|
||||||
|
testLargeChunkedBufferedDownstreamTransformation(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLargeChunkedGzippedBufferedDownstreamTransformation() throws Exception
|
||||||
|
{
|
||||||
|
testLargeChunkedBufferedDownstreamTransformation(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testLargeChunkedBufferedDownstreamTransformation(final boolean gzipped) throws Exception
|
||||||
{
|
{
|
||||||
// Tests the race between a incomplete write performed from ProxyResponseListener.onSuccess()
|
// Tests the race between a incomplete write performed from ProxyResponseListener.onSuccess()
|
||||||
// and ProxyResponseListener.onComplete() being called before the write has completed.
|
// and ProxyResponseListener.onComplete() being called before the write has completed.
|
||||||
|
@ -626,10 +636,18 @@ public class AsyncMiddleManServletTest
|
||||||
@Override
|
@Override
|
||||||
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
ServletOutputStream output = response.getOutputStream();
|
OutputStream output = response.getOutputStream();
|
||||||
|
if (gzipped)
|
||||||
|
{
|
||||||
|
output = new GZIPOutputStream(output);
|
||||||
|
response.setHeader(HttpHeader.CONTENT_ENCODING.asString(), "gzip");
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new Random();
|
||||||
byte[] chunk = new byte[1024 * 1024];
|
byte[] chunk = new byte[1024 * 1024];
|
||||||
for (int i = 0; i < 16; ++i)
|
for (int i = 0; i < 16; ++i)
|
||||||
{
|
{
|
||||||
|
random.nextBytes(chunk);
|
||||||
output.write(chunk);
|
output.write(chunk);
|
||||||
output.flush();
|
output.flush();
|
||||||
}
|
}
|
||||||
|
@ -640,7 +658,10 @@ public class AsyncMiddleManServletTest
|
||||||
@Override
|
@Override
|
||||||
protected ContentTransformer newServerResponseContentTransformer(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Response serverResponse)
|
protected ContentTransformer newServerResponseContentTransformer(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Response serverResponse)
|
||||||
{
|
{
|
||||||
return new BufferingContentTransformer();
|
ContentTransformer transformer = new BufferingContentTransformer();
|
||||||
|
if (gzipped)
|
||||||
|
transformer = new GZIPContentTransformer(transformer);
|
||||||
|
return transformer;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
startClient();
|
startClient();
|
||||||
|
|
Loading…
Reference in New Issue