From 095cf33010523cabcb232d02cc9d8a9682964550 Mon Sep 17 00:00:00 2001 From: Michael Gorovoy Date: Fri, 5 Aug 2011 12:21:32 -0400 Subject: [PATCH] 354014 Improved GzipFilterTest to verify that Content-Length header is passed when mime type is not configured. --- .../jetty/servlets/GzipFilterTest.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterTest.java index 7329e03e838..9b070fff3a0 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterTest.java @@ -69,6 +69,12 @@ public class GzipFilterTest IO.copy(testIn,testOut); testOut.close(); + testFile = testdir.getFile("file.mp3"); + testOut = new BufferedOutputStream(new FileOutputStream(testFile)); + testIn = new ByteArrayInputStream(__content.getBytes("ISO8859_1")); + IO.copy(testIn,testOut); + testOut.close(); + tester=new ServletTester(); tester.setContextPath("/context"); tester.setResourceBase(testdir.getDir().getCanonicalPath()); @@ -86,7 +92,7 @@ public class GzipFilterTest } @Test - public void testGzipFilter() throws Exception + public void testGzip() throws Exception { // generated and parsed test HttpTester request = new HttpTester(); @@ -112,4 +118,32 @@ public class GzipFilterTest assertEquals(__content, testOut.toString("ISO8859_1")); } + + @Test + public void testNotGzip() throws Exception + { + // generated and parsed test + HttpTester request = new HttpTester(); + HttpTester response = new HttpTester(); + + request.setMethod("GET"); + request.setVersion("HTTP/1.0"); + request.setHeader("Host","tester"); + request.setHeader("accept-encoding","gzip"); + request.setURI("/context/file.mp3"); + + ByteArrayBuffer reqsBuff = new ByteArrayBuffer(request.generate().getBytes()); + ByteArrayBuffer respBuff = tester.getResponses(reqsBuff); + response.parse(respBuff.asArray()); + + assertTrue(response.getMethod()==null); + assertEquals(__content.getBytes().length, Integer.parseInt(response.getHeader("Content-Length"))); + assertEquals(HttpServletResponse.SC_OK,response.getStatus()); + + InputStream testIn = new ByteArrayInputStream(response.getContentBytes()); + ByteArrayOutputStream testOut = new ByteArrayOutputStream(); + IO.copy(testIn,testOut); + + assertEquals(__content, testOut.toString("ISO8859_1")); + } }