private void assertIsGzipCompressed(String filename, int filesize) throws Exception { GzipTester tester = new GzipTester(testingdir, compressionType); File testfile = tester.prepareServerFile(testServlet.getSimpleName() + "-" + filename, filesize); FilterHolder holder = tester.setContentServlet(testServlet); holder.setInitParameter("mimeTypes", "text/plain"); try { tester.start(); tester.assertIsResponseGzipCompressed("GET", testfile.getName()); } finally { tester.stop(); } }
@Test public void testExcludePathPatterns() throws Exception { GzipTester tester = new GzipTester(testingdir, compressionType); FilterHolder holder = tester.setContentServlet(DefaultServlet.class); holder.setInitParameter("excludePathPatterns", "/cont.*"); int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE * 4; tester.prepareServerFile("file.txt", filesize); try { tester.start(); tester.assertIsResponseNotGzipCompressed("file.txt", filesize, HttpStatus.OK_200); } finally { tester.stop(); } }
@Test public void testIsGzipCompressedTiny() throws Exception { GzipTester tester = new GzipTester(testingdir, compressionType); // Test content that is smaller than the buffer. int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE / 4; tester.prepareServerFile("file.txt", filesize); FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class); holder.setInitParameter("mimeTypes", "text/plain"); try { tester.start(); HttpTester.Response http = tester.assertIsResponseGzipCompressed("file.txt"); Assert.assertEquals("Accept-Encoding", http.get("Vary")); } finally { tester.stop(); } }
@Test public void testIsNotGzipCompressed() throws Exception { GzipTester tester = new GzipTester(testingdir, compressionType); int filesize = CompressedResponseWrapper.DEFAULT_BUFFER_SIZE * 4; tester.prepareServerFile("file.mp3", filesize); FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class); holder.setInitParameter("mimeTypes", "text/plain"); try { tester.start(); HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("file.mp3", filesize, HttpStatus.OK_200); Assert.assertNull(http.get("Vary")); } finally { tester.stop(); } }
private void assertIsNotGzipCompressed(String filename, int filesize) throws Exception { GzipTester tester = new GzipTester(testingdir, compressionType); File testfile = tester.prepareServerFile(testServlet.getSimpleName() + "-" + filename, filesize); FilterHolder holder = tester.setContentServlet(testServlet); holder.setInitParameter("mimeTypes", "text/plain"); try { tester.start(); HttpTester.Response response = tester.assertIsResponseNotGzipCompressed( "GET", testfile.getName(), filesize, HttpStatus.OK_200); Assert.assertThat(response.get("ETAG"), Matchers.startsWith("W/etag-")); } finally { tester.stop(); } }