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

@ -323,12 +323,16 @@ public class AsyncGzipFilter extends UserAgentFilter implements GzipFactory
{
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

@ -306,11 +306,15 @@ public class GzipFilter extends UserAgentFilter
{
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)
{
@ -637,6 +636,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
{
Assert.assertThat("No servlet defined yet. Did you use #setContentServlet()?",tester,notNullValue());