diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java
index 0050bf4ba86..cf1959fe6fe 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java
@@ -18,8 +18,16 @@
package org.eclipse.jetty.server.handler.gzip;
-import java.io.IOException;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.EnumSet;
+import java.util.concurrent.TimeUnit;
+
+import javax.servlet.DispatcherType;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
@@ -29,7 +37,10 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.servlet.DefaultServlet;
+import org.eclipse.jetty.servlet.FilterHolder;
+import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.TestingDir;
+import org.eclipse.jetty.util.StringUtil;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
@@ -82,19 +93,17 @@ public class GzipDefaultTest
resp.setStatus(_status);
}
}
-
@SuppressWarnings("serial")
public static class HttpContentTypeWithEncoding extends HttpServlet
{
- public static final String COMPRESSED_CONTENT = "
COMPRESSABLE CONTENT
"+
- "This content must be longer than the default min gzip length, which is 256 bytes. "+
- "The moon is blue to a fish in love. How now brown cow. The quick brown fox jumped over the lazy dog. A woman needs a man like a fish needs a bicycle!"+
- "";
-
+ public static final String COMPRESSED_CONTENT = "COMPRESSABLE CONTENT
"
+ + "This content must be longer than the default min gzip length, which is 256 bytes. "
+ + "The moon is blue to a fish in love. How now brown cow. The quick brown fox jumped over the lazy dog. A woman needs a man like a fish needs a bicycle!"
+ + "";
+
@Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
resp.setContentType("text/plain;charset=UTF8");
resp.setStatus(200);
@@ -107,80 +116,107 @@ public class GzipDefaultTest
@Rule
public TestingDir testingdir = new TestingDir();
-
-
@Test
public void testIsGzipByMethod() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
+ // Configure Gzip Handler
+ tester.getGzipHandler().setIncludedMethods("POST","WIBBLE");
+
+ // Prepare Server File
int filesize = tester.getOutputBufferSize() * 2;
tester.prepareServerFile("file.txt",filesize);
-
+
+ // Content Servlet
tester.setContentServlet(GetServlet.class);
- tester.getGzipHandler().setIncludedMethods("POST","WIBBLE");
-
+
try
{
tester.start();
+ HttpTester.Response response;
+
tester.assertIsResponseGzipCompressed("POST","file.txt");
tester.assertIsResponseGzipCompressed("WIBBLE","file.txt");
- tester.assertIsResponseNotGzipCompressed("GET","file.txt",filesize,200);
+
+ response = tester.executeRequest("GET","/context/file.txt",2,TimeUnit.SECONDS);
+
+ assertThat("Response status",response.getStatus(),is(HttpStatus.OK_200));
+ assertThat("Content-Encoding",response.get("Content-Encoding"),not(containsString(compressionType)));
+
+ String content = tester.readResponse(response);
+ assertThat("Response content size",content.length(),is(filesize));
+ String expectedContent = IO.readToString(testingdir.getFile("file.txt"));
+ assertThat("Response content",content,is(expectedContent));
}
finally
{
tester.stop();
}
}
-
+
@SuppressWarnings("serial")
public static class GetServlet extends DefaultServlet
{
public GetServlet()
- {
+ {
super();
}
-
+
@Override
- public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,ServletException
+ public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
{
- String uri=req.getRequestURI();
+ String uri = req.getRequestURI();
if (uri.endsWith(".deferred"))
{
// System.err.println("type for "+uri.substring(0,uri.length()-9)+" is "+getServletContext().getMimeType(uri.substring(0,uri.length()-9)));
- resp.setContentType(getServletContext().getMimeType(uri.substring(0,uri.length()-9)));
+ resp.setContentType(getServletContext().getMimeType(uri.substring(0,uri.length() - 9)));
}
-
+
doGet(req,resp);
}
}
-
-
-
+
@Test
public void testIsGzipCompressedEmpty() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
+ // Configure Gzip Handler
+ tester.getGzipHandler().addIncludedMimeTypes("text/plain");
+
+ // Prepare server file
tester.prepareServerFile("empty.txt",0);
-
- tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
+
+ // Set content servlet
+ tester.setContentServlet(DefaultServlet.class);
try
{
tester.start();
- tester.assertIsResponseNotGzipCompressed("GET","empty.txt",0,200);
+
+ HttpTester.Response response;
+
+ response = tester.executeRequest("GET","/context/empty.txt",2,TimeUnit.SECONDS);
+
+ assertThat("Response status",response.getStatus(),is(HttpStatus.OK_200));
+ assertThat("Content-Encoding",response.get("Content-Encoding"),not(containsString(compressionType)));
+
+ String content = tester.readResponse(response);
+ assertThat("Response content size",content.length(),is(0));
+ String expectedContent = IO.readToString(testingdir.getFile("empty.txt"));
+ assertThat("Response content",content,is(expectedContent));
}
finally
{
tester.stop();
}
}
-
+
@Test
public void testIsGzipCompressedTiny() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
int filesize = tester.getOutputBufferSize() / 4;
tester.prepareServerFile("file.txt",filesize);
@@ -198,11 +234,11 @@ public class GzipDefaultTest
tester.stop();
}
}
-
+
@Test
public void testIsGzipCompressedLarge() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.txt",filesize);
@@ -221,22 +257,21 @@ public class GzipDefaultTest
tester.stop();
}
}
-
@Test
public void testGzipedIfModified() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.txt",filesize);
-
+
tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
try
{
tester.start();
- HttpTester.Response http = tester.assertIsResponseGzipCompressed("GET","file.txt",System.currentTimeMillis()-4000);
+ HttpTester.Response http = tester.assertIsResponseGzipCompressed("GET","file.txt",System.currentTimeMillis() - 4000);
Assert.assertEquals("Accept-Encoding, User-Agent",http.get("Vary"));
}
finally
@@ -244,11 +279,11 @@ public class GzipDefaultTest
tester.stop();
}
}
-
+
@Test
public void testGzippedIfSVG() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
tester.copyTestServerFile("test.svg");
tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
@@ -257,7 +292,7 @@ public class GzipDefaultTest
try
{
tester.start();
- HttpTester.Response http = tester.assertIsResponseGzipCompressed("GET","test.svg",System.currentTimeMillis()-4000);
+ HttpTester.Response http = tester.assertIsResponseGzipCompressed("GET","test.svg",System.currentTimeMillis() - 4000);
Assert.assertEquals("Accept-Encoding, User-Agent",http.get("Vary"));
}
finally
@@ -269,40 +304,44 @@ public class GzipDefaultTest
@Test
public void testNotGzipedIfNotModified() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.txt",filesize);
-
+
tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
try
{
tester.start();
- tester.assertIsResponseNotModified("GET","file.txt",System.currentTimeMillis()+4000);
+ tester.assertIsResponseNotModified("GET","file.txt",System.currentTimeMillis() + 4000);
}
finally
{
tester.stop();
}
}
-
@Test
public void testIsNotGzipCompressedWithZeroQ() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType+"; q=0");
-
+ GzipTester tester = new GzipTester(testingdir,compressionType + "; q=0");
+
+ // Configure Gzip Handler
+ tester.getGzipHandler().addIncludedMimeTypes("text/plain");
+
+ // Prepare server file
int filesize = tester.getOutputBufferSize() / 4;
tester.prepareServerFile("file.txt",filesize);
-
- tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
+
+ // Add content servlet
+ tester.setContentServlet(DefaultServlet.class);
try
{
tester.start();
- HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("GET","file.txt", filesize, HttpStatus.OK_200);
- Assert.assertEquals("Accept-Encoding, User-Agent",http.get("Vary"));
+ HttpTester.Response http = assertIsResponseNotGzipCompressed(tester,"GET","file.txt",filesize,HttpStatus.OK_200);
+ assertThat("Response[Vary]",http.get("Vary"),containsString("Accept-Encoding"));
}
finally
{
@@ -313,11 +352,11 @@ public class GzipDefaultTest
@Test
public void testIsGzipCompressedWithQ() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType,"something;q=0.1,"+compressionType+";q=0.5");
-
+ GzipTester tester = new GzipTester(testingdir,compressionType,"something;q=0.1," + compressionType + ";q=0.5");
+
int filesize = tester.getOutputBufferSize() / 4;
tester.prepareServerFile("file.txt",filesize);
-
+
tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
tester.getGzipHandler().setExcludedAgentPatterns();
@@ -332,21 +371,23 @@ public class GzipDefaultTest
tester.stop();
}
}
-
+
@Test
public void testIsNotGzipCompressedByContentType() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
+ // Prepare server file
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.mp3",filesize);
- tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
+ // Add content servlet
+ tester.setContentServlet(DefaultServlet.class);
try
{
tester.start();
- HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("GET","file.mp3", filesize, HttpStatus.OK_200);
+ HttpTester.Response http = assertIsResponseNotGzipCompressed(tester,"GET","file.mp3",filesize,HttpStatus.OK_200);
Assert.assertNull(http.get("Vary"));
}
finally
@@ -354,23 +395,26 @@ public class GzipDefaultTest
tester.stop();
}
}
-
-
+
@Test
public void testIsNotGzipCompressedByExcludedContentType() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
+ // Configure Gzip Handler
+ tester.getGzipHandler().addExcludedMimeTypes("text/plain");
+
+ // Prepare server file
int filesize = tester.getOutputBufferSize() * 4;
- tester.prepareServerFile("test_quotes.txt", filesize);
-
- tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
- tester.getGzipHandler().setExcludedMimeTypes("text/plain");
+ tester.prepareServerFile("test_quotes.txt",filesize);
+
+ // Add content servlet
+ tester.setContentServlet(DefaultServlet.class);
try
{
tester.start();
- HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("GET","test_quotes.txt", filesize, HttpStatus.OK_200);
+ HttpTester.Response http = assertIsResponseNotGzipCompressed(tester,"GET","test_quotes.txt",filesize,HttpStatus.OK_200);
Assert.assertNull(http.get("Vary"));
}
finally
@@ -378,24 +422,27 @@ public class GzipDefaultTest
tester.stop();
}
}
-
-
+
@Test
public void testIsNotGzipCompressedByExcludedContentTypeWithCharset() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
+ // Configure Gzip Handler
+ tester.getGzipHandler().addExcludedMimeTypes("text/plain");
+
+ // Prepare server file
int filesize = tester.getOutputBufferSize() * 4;
- tester.prepareServerFile("test_quotes.txt", filesize);
+ tester.prepareServerFile("test_quotes.txt",filesize);
tester.addMimeType("txt","text/plain;charset=UTF-8");
- tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class);
- tester.getGzipHandler().addExcludedMimeTypes("text/plain");
+ // Add content servlet
+ tester.setContentServlet(DefaultServlet.class);
try
{
tester.start();
- HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("GET","test_quotes.txt", filesize, HttpStatus.OK_200);
+ HttpTester.Response http = assertIsResponseNotGzipCompressed(tester,"GET","test_quotes.txt",filesize,HttpStatus.OK_200);
Assert.assertNull(http.get("Vary"));
}
finally
@@ -403,18 +450,18 @@ public class GzipDefaultTest
tester.stop();
}
}
-
+
@Test
public void testGzipCompressedByContentTypeWithEncoding() throws Exception
- {
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ {
+ GzipTester tester = new GzipTester(testingdir,compressionType);
tester.setContentServlet(HttpContentTypeWithEncoding.class);
tester.getGzipHandler().addIncludedMimeTypes("text/plain");
tester.getGzipHandler().setExcludedAgentPatterns();
try
{
tester.start();
- HttpTester.Response http = tester.assertNonStaticContentIsResponseGzipCompressed("GET","xxx", HttpContentTypeWithEncoding.COMPRESSED_CONTENT);
+ HttpTester.Response http = tester.assertNonStaticContentIsResponseGzipCompressed("GET","xxx",HttpContentTypeWithEncoding.COMPRESSED_CONTENT);
Assert.assertEquals("Accept-Encoding",http.get("Vary"));
}
finally
@@ -422,34 +469,41 @@ public class GzipDefaultTest
tester.stop();
}
}
-
-
+
@Test
public void testIsNotGzipCompressedByDeferredContentType() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
+ // Configure Gzip Handler
+ tester.getGzipHandler().addIncludedMimeTypes("text/plain");
+
+ // Prepare server file
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.mp3.deferred",filesize);
-
+
+ // Add content servlet
tester.setContentServlet(GetServlet.class);
try
{
tester.start();
- HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("GET","file.mp3.deferred", filesize, HttpStatus.OK_200);
- Assert.assertNull(http.get("Vary"));
+ HttpTester.Response response = assertIsResponseNotGzipCompressed(tester,"GET","file.mp3.deferred",filesize,HttpStatus.OK_200);
+ assertThat("Response[Vary]", response.get("Vary"), isEmptyOrNullString());
}
finally
{
tester.stop();
}
}
-
+
@Test
public void testIsNotGzipCompressedHttpStatus() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
+
+ // Configure Gzip Handler
+ tester.getGzipHandler().addIncludedMimeTypes("text/plain");
// Test error code 204
tester.setContentServlet(HttpStatusServlet.class);
@@ -457,7 +511,11 @@ public class GzipDefaultTest
try
{
tester.start();
- tester.assertIsResponseNotGzipCompressed("GET",-1, 204);
+
+ HttpTester.Response response = tester.executeRequest("GET","/context/",2,TimeUnit.SECONDS);
+
+ assertThat("Response status",response.getStatus(),is(HttpStatus.NO_CONTENT_204));
+ assertThat("Content-Encoding",response.get("Content-Encoding"),not(containsString(compressionType)));
}
finally
{
@@ -469,7 +527,10 @@ public class GzipDefaultTest
@Test
public void testIsNotGzipCompressedHttpBadRequestStatus() throws Exception
{
- GzipTester tester = new GzipTester(testingdir, compressionType);
+ GzipTester tester = new GzipTester(testingdir,compressionType);
+
+ // Configure Gzip Handler
+ tester.getGzipHandler().addIncludedMimeTypes("text/plain");
// Test error code 400
tester.setContentServlet(HttpErrorServlet.class);
@@ -477,32 +538,42 @@ public class GzipDefaultTest
try
{
tester.start();
- tester.assertIsResponseNotGzipCompressedAndEqualToExpectedString("GET","error message", -1, 400);
+
+ HttpTester.Response response = tester.executeRequest("GET","/context/",2,TimeUnit.SECONDS);
+
+ assertThat("Response status",response.getStatus(),is(HttpStatus.BAD_REQUEST_400));
+ assertThat("Content-Encoding",response.get("Content-Encoding"),not(containsString(compressionType)));
+
+ String content = tester.readResponse(response);
+ assertThat("Response content",content,is("error message"));
}
finally
{
tester.stop();
}
-
}
@Test
public void testUserAgentExclusion() throws Exception
{
GzipTester tester = new GzipTester(testingdir,compressionType);
-
- tester.setContentServlet(DefaultServlet.class);
- tester.getGzipHandler().setExcludedAgentPatterns("bar","foo");
-
tester.setUserAgent("foo");
+ // Configure Gzip Handler
+ tester.getGzipHandler().addIncludedMimeTypes("text/plain");
+ tester.getGzipHandler().setExcludedAgentPatterns("bar","foo");
+
+ // Prepare server file
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.txt",filesize);
+ // Add content servlet
+ tester.setContentServlet(DefaultServlet.class);
+
try
{
tester.start();
- tester.assertIsResponseNotGzipCompressed("GET","file.txt",filesize,HttpStatus.OK_200);
+ assertIsResponseNotGzipCompressed(tester,"GET","file.txt",filesize,HttpStatus.OK_200);
}
finally
{
@@ -514,9 +585,7 @@ public class GzipDefaultTest
public void testUserAgentExclusionDefault() throws Exception
{
GzipTester tester = new GzipTester(testingdir,compressionType);
-
tester.setContentServlet(DefaultServlet.class);
-
tester.setUserAgent("Some MSIE 6.0 user-agent");
int filesize = tester.getOutputBufferSize() * 4;
@@ -525,7 +594,7 @@ public class GzipDefaultTest
try
{
tester.start();
- HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("GET","file.txt",filesize,HttpStatus.OK_200);
+ HttpTester.Response http = assertIsResponseNotGzipCompressed(tester,"GET","file.txt",filesize,HttpStatus.OK_200);
Assert.assertEquals("Accept-Encoding, User-Agent",http.get("Vary"));
}
finally
@@ -538,18 +607,22 @@ public class GzipDefaultTest
public void testUserAgentExclusionByExcludedAgentPatterns() throws Exception
{
GzipTester tester = new GzipTester(testingdir,compressionType);
-
- tester.setContentServlet(DefaultServlet.class);
- tester.getGzipHandler().setExcludedAgentPatterns("bar","fo.*");
tester.setUserAgent("foo");
+ // Configure Gzip Handler
+ tester.getGzipHandler().setExcludedAgentPatterns("bar","fo.*");
+
+ // Prepare server file
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.txt",filesize);
+ // Set content servlet
+ tester.setContentServlet(DefaultServlet.class);
+
try
{
tester.start();
- tester.assertIsResponseNotGzipCompressed("GET","file.txt",filesize,HttpStatus.OK_200);
+ assertIsResponseNotGzipCompressed(tester,"GET","file.txt",filesize,HttpStatus.OK_200);
}
finally
{
@@ -562,16 +635,20 @@ public class GzipDefaultTest
{
GzipTester tester = new GzipTester(testingdir,compressionType);
- tester.setContentServlet(DefaultServlet.class);
+ // Configure Gzip Handler
tester.getGzipHandler().setExcludedPaths("*.txt");
+ // Prepare server file
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.txt",filesize);
+ // Set content servlet
+ tester.setContentServlet(DefaultServlet.class);
+
try
{
tester.start();
- tester.assertIsResponseNotGzipCompressed("GET","file.txt",filesize,HttpStatus.OK_200);
+ assertIsResponseNotGzipCompressed(tester,"GET","file.txt",filesize,HttpStatus.OK_200);
}
finally
{
@@ -584,13 +661,17 @@ public class GzipDefaultTest
{
GzipTester tester = new GzipTester(testingdir,compressionType);
- tester.setContentServlet(DefaultServlet.class);
+ // Configure Gzip Handler
tester.getGzipHandler().setExcludedPaths("*.txt");
tester.getGzipHandler().setIncludedPaths("/file.txt");
+ // Prepare server file
int filesize = tester.getOutputBufferSize() * 4;
tester.prepareServerFile("file.txt",filesize);
+ // Set content servlet
+ tester.setContentServlet(DefaultServlet.class);
+
try
{
tester.start();
@@ -602,7 +683,45 @@ public class GzipDefaultTest
}
}
-
+ public HttpTester.Response assertIsResponseNotGzipCompressed(GzipTester tester, String method, String filename, int expectedFilesize, int status)
+ throws Exception
+ {
+ HttpTester.Response response = tester.executeRequest(method,"/context/" + filename,2,TimeUnit.SECONDS);
+
+ assertThat("Response status",response.getStatus(),is(status));
+ assertThat("Content-Encoding",response.get("Content-Encoding"),not(containsString(compressionType)));
+
+ assertResponseContent(tester,response,status,filename,expectedFilesize);
+
+ return response;
+ }
+
+ private void assertResponseContent(GzipTester tester, HttpTester.Response response, int status, String filename, int expectedFilesize) throws IOException,
+ UnsupportedEncodingException
+ {
+ if (expectedFilesize >= 0)
+ {
+ assertThat("filename",filename,notNullValue());
+ assertThat("Response contentBytes.length",response.getContentBytes().length,is(expectedFilesize));
+ String contentLength = response.get("Content-Length");
+ if (StringUtil.isNotBlank(contentLength))
+ {
+ assertThat("Content-Length",response.get("Content-Length"),is(Integer.toString(expectedFilesize)));
+ }
+
+ if (status >= 200 && status < 300)
+ {
+ assertThat("ETag",response.get("ETAG"),startsWith("W/"));
+ }
+
+ File serverFile = testingdir.getFile(filename);
+ String expectedResponse = IO.readToString(serverFile);
+
+ String actual = tester.readResponse(response);
+ Assert.assertEquals("Expected response equals actual response",expectedResponse,actual);
+ }
+ }
+
@Test
public void testIsNotGzipCompressedSVGZ() throws Exception
@@ -611,10 +730,11 @@ public class GzipDefaultTest
tester.setContentServlet(DefaultServlet.class);
tester.copyTestServerFile("test.svgz");
+
try
{
tester.start();
- tester.assertIsResponseNotGzipFiltered("test.svgz", "test.svgz.sha1", "image/svg+xml", "gzip");
+ tester.assertIsResponseNotGzipFiltered("test.svgz","test.svgz.sha1","image/svg+xml","gzip");
}
finally
{
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipTester.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipTester.java
index 07d53c4dec3..0a288166077 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipTester.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipTester.java
@@ -40,7 +40,6 @@ import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import javax.servlet.DispatcherType;
-import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServletResponse;
@@ -77,7 +76,6 @@ public class GzipTester
}
}
- private Class extends Filter> gzipFilterClass = null;
private String encoding = "ISO8859_1";
private String userAgent = null;
private final ServletTester tester = new ServletTester("/context",ServletContextHandler.GZIP);
@@ -438,95 +436,6 @@ public class GzipTester
return mat.group();
}
- /**
- * Asserts that the requested filename results in a properly structured GzipFilter response, where the content is not compressed, and the content-length is
- * returned appropriately.
- *
- * @param filename
- * the filename used for the request, and also used to compare the response to the server file, assumes that the file is suitable for
- * {@link Assert#assertEquals(Object, Object)} use. (in other words, the contents of the file are text)
- * @param expectedFilesize
- * the expected filesize to be specified on the Content-Length portion of the response headers. (note: passing -1 will disable the Content-Length
- * assertion)
- * @throws Exception
- */
- public HttpTester.Response assertIsResponseNotGzipCompressed(String method, String filename, int expectedFilesize, int status) throws Exception
- {
- String uri = "/context/" + filename;
- HttpTester.Response response = executeRequest(method,uri);
- assertResponseHeaders(expectedFilesize,status,response);
- // Assert that the contents are what we expect.
- if (filename != null)
- {
- File serverFile = testdir.getFile(filename);
- String expectedResponse = IO.readToString(serverFile);
-
- String actual = readResponse(response);
- Assert.assertEquals("Expected response equals actual response",expectedResponse,actual);
- }
-
- return response;
- }
-
- /**
- * Asserts that the request results in a properly structured GzipFilter response, where the content is not compressed, and the content-length is returned
- * appropriately.
- *
- * @param expectedResponse
- * the expected response body string
- * @param expectedFilesize
- * the expected filesize to be specified on the Content-Length portion of the response headers. (note: passing -1 will disable the Content-Length
- * assertion)
- * @throws Exception
- */
- public void assertIsResponseNotGzipCompressedAndEqualToExpectedString(String method, String expectedResponse, int expectedFilesize, int status)
- throws Exception
- {
- String uri = "/context/";
- HttpTester.Response response = executeRequest(method,uri);
- assertResponseHeaders(expectedFilesize,status,response);
-
- String actual = readResponse(response);
- Assert.assertEquals("Expected response equals actual response",expectedResponse,actual);
- }
-
- /**
- * Asserts that the request results in a properly structured GzipFilter response, where the content is not compressed, and the content-length is returned
- * appropriately.
- *
- * @param expectedFilesize
- * the expected filesize to be specified on the Content-Length portion of the response headers. (note: passing -1 will disable the Content-Length
- * assertion)
- * @throws Exception
- */
- public void assertIsResponseNotGzipCompressed(String method, int expectedFilesize, int status) throws Exception
- {
- String uri = "/context/";
- HttpTester.Response response = executeRequest(method,uri);
- assertResponseHeaders(expectedFilesize,status,response);
- }
-
- private void assertResponseHeaders(int expectedFilesize, int status, HttpTester.Response response)
- {
- Assert.assertThat("Response.status",response.getStatus(),is(status));
- Assert.assertThat("Response.header[Content-Encoding]",response.get("Content-Encoding"),not(containsString(compressionType)));
- if (expectedFilesize != (-1))
- {
- Assert.assertEquals(expectedFilesize,response.getContentBytes().length);
- String cl = response.get("Content-Length");
- if (cl != null)
- {
- int serverLength = Integer.parseInt(response.get("Content-Length"));
- Assert.assertEquals(serverLength,expectedFilesize);
- }
-
- if (status >= 200 && status < 300)
- Assert.assertThat(response.get("ETAG"),Matchers.startsWith("W/"));
-
- }
- Assert.assertThat("Response.header[Content-Encoding]",response.get("Content-Encoding"),not(containsString(compressionType)));
- }
-
public HttpTester.Response executeRequest(String method, String path, int idleFor, TimeUnit idleUnit) throws Exception
{
HttpTester.Request request = HttpTester.newRequest();
@@ -548,12 +457,7 @@ public class GzipTester
return HttpTester.parseResponse(tester.getResponses(request.generate(),idleFor,idleUnit));
}
- private HttpTester.Response executeRequest(String method, String path) throws IOException, Exception
- {
- return executeRequest(method,path,2,TimeUnit.SECONDS);
- }
-
- private String readResponse(HttpTester.Response response) throws IOException, UnsupportedEncodingException
+ public String readResponse(HttpTester.Response response) throws IOException, UnsupportedEncodingException
{
String actual = null;
InputStream in = null;
@@ -677,12 +581,6 @@ public class GzipTester
ServletHolder servletHolder = tester.addServlet(servletClass,"/");
servletHolder.setInitParameter("baseDir",testdir.getDir().getAbsolutePath());
servletHolder.setInitParameter("etags","true");
-
- if (gzipFilterClass != null)
- {
- FilterHolder holder = tester.addFilter(gzipFilterClass,"/*",EnumSet.of(DispatcherType.REQUEST));
- holder.setInitParameter("vary","Accept-Encoding");
- }
}
public void setEncoding(String encoding)