450855 GzipFilter MIGHT_COMPRESS exception

Disabled tests that tried to apply the GzipFilter to default async content generation.  These
tests will never work as GzipFilter wraps the response and the default async does not preserve wrappers.

For the MIGHT_COMPRESS issue, improved the filter to handle the case that it has already been applied to
a request/response and that the state is already mightCompress.
This commit is contained in:
Greg Wilkins 2014-11-12 10:20:06 +11:00
parent f04903fb68
commit 5165d4c7ad
4 changed files with 26 additions and 3 deletions

View File

@ -28,6 +28,7 @@ import java.util.StringTokenizer;
import java.util.regex.Pattern;
import java.util.zip.Deflater;
import javax.servlet.DispatcherType;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
@ -302,6 +303,19 @@ public class AsyncGzipFilter extends UserAgentFilter implements GzipFactory
LOG.debug("{} doFilter {}",this,req);
HttpServletRequest request=(HttpServletRequest)req;
HttpServletResponse response=(HttpServletResponse)res;
HttpChannel<?> channel = HttpChannel.getCurrentHttpChannel();
// Have we already started compressing this response?
if (req.getDispatcherType()!=DispatcherType.REQUEST)
{
HttpOutput out = channel.getResponse().getHttpOutput();
if (out instanceof GzipHttpOutput && ((GzipHttpOutput)out).mightCompress())
{
LOG.debug("{} already might compress {}",this,request);
super.doFilter(request,response,chain);
return;
}
}
// If not a supported method or it is an Excluded URI or an excluded UA - no Vary because no matter what client, this URI is always excluded
String requestURI = request.getRequestURI();
@ -368,7 +382,6 @@ public class AsyncGzipFilter extends UserAgentFilter implements GzipFactory
request.setAttribute(ETAG,etag.replace(ETAG_GZIP,""));
}
HttpChannel<?> channel = HttpChannel.getCurrentHttpChannel();
HttpOutput out = channel.getResponse().getHttpOutput();
if (!(out instanceof GzipHttpOutput))
{

View File

@ -248,6 +248,10 @@ public class GzipHttpOutput extends HttpOutput
}
}
public boolean mightCompress()
{
return _state.get()==GZState.MIGHT_COMPRESS;
}
public void mightCompress(GzipFactory factory)
{

View File

@ -49,6 +49,7 @@ import org.eclipse.jetty.servlets.gzip.TestServletTypeLengthStreamWrite;
import org.eclipse.jetty.servlets.gzip.TestServletTypeStreamLengthWrite;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@ -63,7 +64,6 @@ import org.junit.runners.Parameterized.Parameters;
* @see <a href="Eclipse Bug 354014">http://bugs.eclipse.org/354014</a>
*/
@RunWith(Parameterized.class)
@Ignore
public class GzipFilterContentLengthTest
{
@Rule
@ -167,6 +167,8 @@ public class GzipFilterContentLengthTest
@Test
public void testAsyncTimeoutCompleteWrite_Default() throws Exception
{
if (expectCompressed && gzipFilterClass==GzipFilter.class)
return; // Default startAsync will never work with GzipFilter, which needs wrapping
testWithGzip(AsyncTimeoutCompleteWrite.Default.class);
}
@ -187,6 +189,8 @@ public class GzipFilterContentLengthTest
@Test
public void testAsyncTimeoutDispatchWrite_Default() throws Exception
{
if (expectCompressed && gzipFilterClass==GzipFilter.class)
return; // Default startAsync will never work with GzipFilter, which needs wrapping
testWithGzip(AsyncTimeoutDispatchWrite.Default.class);
}
@ -207,6 +211,8 @@ public class GzipFilterContentLengthTest
@Test
public void testAsyncScheduledDispatchWrite_Default() throws Exception
{
if (expectCompressed && gzipFilterClass==GzipFilter.class)
return; // Default startAsync will never work with GzipFilter, which needs wrapping
testWithGzip(AsyncScheduledDispatchWrite.Default.class);
}

View File

@ -90,7 +90,7 @@ public abstract class AsyncTimeoutCompleteWrite extends TestDirContentServlet im
String fileName = request.getServletPath();
request.setAttribute("filename",fileName);
ctx.addListener(this);
ctx.setTimeout(200);
ctx.setTimeout(20);
// Setup indication of a redispatch (which this scenario shouldn't do)
request.setAttribute(this.getClass().getName(),ctx);