439201 GzipFilter and AsyncGzipFilter should strip charset from Content-Type before making exclusion comparison in doFilter
This commit is contained in:
parent
10da0e1015
commit
5969638e69
|
@ -317,18 +317,22 @@ public class AsyncGzipFilter extends UserAgentFilter implements GzipFactory
|
||||||
super.doFilter(request,response,chain);
|
super.doFilter(request,response,chain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclude non compressible mime-types known from URI extension. - no Vary because no matter what client, this URI is always excluded
|
// 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)
|
if (_mimeTypes.size()>0 && _excludeMimeTypes)
|
||||||
{
|
{
|
||||||
String mimeType = _context.getMimeType(request.getRequestURI());
|
String mimeType = _context.getMimeType(request.getRequestURI());
|
||||||
|
|
||||||
if (mimeType!=null && _mimeTypes.contains(mimeType))
|
if (mimeType!=null)
|
||||||
{
|
{
|
||||||
LOG.debug("{} excluded by path suffix {}",this,request);
|
mimeType = MimeTypes.getContentTypeWithoutCharset(mimeType);
|
||||||
// handle normally without setting vary header
|
if (_mimeTypes.contains(mimeType))
|
||||||
super.doFilter(request,response,chain);
|
{
|
||||||
return;
|
LOG.debug("{} excluded by path suffix {}",this,request);
|
||||||
|
// handle normally without setting vary header
|
||||||
|
super.doFilter(request,response,chain);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -300,17 +300,21 @@ public class GzipFilter extends UserAgentFilter
|
||||||
super.doFilter(request,response,chain);
|
super.doFilter(request,response,chain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclude non compressible mime-types known from URI extension. - no Vary because no matter what client, this URI is always excluded
|
// 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)
|
if (_mimeTypes.size()>0 && _excludeMimeTypes)
|
||||||
{
|
{
|
||||||
String mimeType = _context.getMimeType(request.getRequestURI());
|
String mimeType = _context.getMimeType(request.getRequestURI());
|
||||||
|
|
||||||
if (mimeType!=null && _mimeTypes.contains(mimeType))
|
if (mimeType!=null)
|
||||||
{
|
{
|
||||||
// handle normally without setting vary header
|
mimeType = MimeTypes.getContentTypeWithoutCharset(mimeType);
|
||||||
super.doFilter(request,response,chain);
|
if (_mimeTypes.contains(mimeType))
|
||||||
return;
|
{
|
||||||
|
// handle normally without setting vary header
|
||||||
|
super.doFilter(request,response,chain);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
@Test
|
||||||
public void testGzipCompressedByContentTypeWithEncoding() throws Exception
|
public void testGzipCompressedByContentTypeWithEncoding() throws Exception
|
||||||
{
|
{
|
||||||
|
|
|
@ -395,7 +395,6 @@ public class GzipTester
|
||||||
String uri = "/context/"+filename;
|
String uri = "/context/"+filename;
|
||||||
HttpTester.Response response = executeRequest(method,uri);
|
HttpTester.Response response = executeRequest(method,uri);
|
||||||
assertResponseHeaders(expectedFilesize,status,response);
|
assertResponseHeaders(expectedFilesize,status,response);
|
||||||
|
|
||||||
// Assert that the contents are what we expect.
|
// Assert that the contents are what we expect.
|
||||||
if (filename != null)
|
if (filename != null)
|
||||||
{
|
{
|
||||||
|
@ -636,6 +635,11 @@ public class GzipTester
|
||||||
{
|
{
|
||||||
this.userAgent = ua;
|
this.userAgent = ua;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addMimeType (String extension, String mimetype)
|
||||||
|
{
|
||||||
|
this.tester.getContext().getMimeTypes().addMimeMapping(extension, mimetype);
|
||||||
|
}
|
||||||
|
|
||||||
public void start() throws Exception
|
public void start() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue