439201 GzipFilter and AsyncGzipFilter should strip charset from Content-Type before making exclusion comparison in doFilter

This commit is contained in:
Jan Bartel 2014-07-09 18:01:07 +10:00
parent 10da0e1015
commit 5969638e69
4 changed files with 80 additions and 14 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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
{

View File

@ -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
{