diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/AsyncGzipFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/AsyncGzipFilter.java index 6eb7c152aa3..7b62a57bd77 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/AsyncGzipFilter.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/AsyncGzipFilter.java @@ -317,18 +317,22 @@ public class AsyncGzipFilter extends UserAgentFilter implements GzipFactory super.doFilter(request,response,chain); return; } - + // Exclude non compressible mime-types known from URI extension. - no Vary because no matter what client, this URI is always excluded if (_mimeTypes.size()>0 && _excludeMimeTypes) { String mimeType = _context.getMimeType(request.getRequestURI()); - - if (mimeType!=null && _mimeTypes.contains(mimeType)) + + if (mimeType!=null) { - LOG.debug("{} excluded by path suffix {}",this,request); - // handle normally without setting vary header - super.doFilter(request,response,chain); - return; + mimeType = MimeTypes.getContentTypeWithoutCharset(mimeType); + if (_mimeTypes.contains(mimeType)) + { + LOG.debug("{} excluded by path suffix {}",this,request); + // handle normally without setting vary header + super.doFilter(request,response,chain); + return; + } } } diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java index 69f2f62f119..0343034d333 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java @@ -300,17 +300,21 @@ public class GzipFilter extends UserAgentFilter super.doFilter(request,response,chain); return; } - + // Exclude non compressible mime-types known from URI extension. - no Vary because no matter what client, this URI is always excluded if (_mimeTypes.size()>0 && _excludeMimeTypes) { String mimeType = _context.getMimeType(request.getRequestURI()); - - if (mimeType!=null && _mimeTypes.contains(mimeType)) + + if (mimeType!=null) { - // handle normally without setting vary header - super.doFilter(request,response,chain); - return; + mimeType = MimeTypes.getContentTypeWithoutCharset(mimeType); + if (_mimeTypes.contains(mimeType)) + { + // handle normally without setting vary header + super.doFilter(request,response,chain); + return; + } } } diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java index bdcac4218d1..0454bb5ee49 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterDefaultTest.java @@ -389,6 +389,60 @@ public class GzipFilterDefaultTest } } + + @Test + public void testIsNotGzipCompressedByExcludedContentType() throws Exception + { + GzipTester tester = new GzipTester(testingdir, compressionType); + tester.setGzipFilterClass(testFilter); + + int filesize = tester.getOutputBufferSize() * 4; + tester.prepareServerFile("test_quotes.txt", filesize); + + + FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class); + holder.setInitParameter("excludedMimeTypes","text/plain"); + + try + { + tester.start(); + HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("GET","test_quotes.txt", filesize, HttpStatus.OK_200); + Assert.assertNull(http.get("Vary")); + } + finally + { + tester.stop(); + } + } + + + @Test + public void testIsNotGzipCompressedByExcludedContentTypeWithCharset() throws Exception + { + GzipTester tester = new GzipTester(testingdir, compressionType); + tester.setGzipFilterClass(testFilter); + + int filesize = tester.getOutputBufferSize() * 4; + tester.prepareServerFile("test_quotes.txt", filesize); + tester.addMimeType("txt","text/plain;charset=UTF-8"); + + FilterHolder holder = tester.setContentServlet(org.eclipse.jetty.servlet.DefaultServlet.class); + holder.setInitParameter("excludedMimeTypes","text/plain"); + + try + { + tester.start(); + HttpTester.Response http = tester.assertIsResponseNotGzipCompressed("GET","test_quotes.txt", filesize, HttpStatus.OK_200); + Assert.assertNull(http.get("Vary")); + } + finally + { + tester.stop(); + } + } + + + @Test public void testGzipCompressedByContentTypeWithEncoding() throws Exception { diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java index 657c6dfc85b..66bf12a58b8 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java @@ -395,7 +395,6 @@ public class GzipTester 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) { @@ -636,6 +635,11 @@ public class GzipTester { this.userAgent = ua; } + + public void addMimeType (String extension, String mimetype) + { + this.tester.getContext().getMimeTypes().addMimeMapping(extension, mimetype); + } public void start() throws Exception {