Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2014-11-11 18:20:06 -0500
committerGreg Wilkins2014-11-11 18:20:06 -0500
commit5165d4c7ade39b4107d4f09bf78ea79a1815fe30 (patch)
tree428e0d7aee536e4c2e4388a2668fd1602a5270b5 /jetty-servlets
parentf04903fb6881331efda78ee768a278f87cba51b7 (diff)
downloadorg.eclipse.jetty.project-5165d4c7ade39b4107d4f09bf78ea79a1815fe30.tar.gz
org.eclipse.jetty.project-5165d4c7ade39b4107d4f09bf78ea79a1815fe30.tar.xz
org.eclipse.jetty.project-5165d4c7ade39b4107d4f09bf78ea79a1815fe30.zip
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.
Diffstat (limited to 'jetty-servlets')
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/AsyncGzipFilter.java15
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/gzip/GzipHttpOutput.java4
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java8
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutCompleteWrite.java2
4 files changed, 26 insertions, 3 deletions
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 2cdeb9c60c..7cc75b8c6d 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
@@ -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))
{
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/gzip/GzipHttpOutput.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/gzip/GzipHttpOutput.java
index d56b2e55f5..9337b6cced 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/gzip/GzipHttpOutput.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/gzip/GzipHttpOutput.java
@@ -248,6 +248,10 @@ public class GzipHttpOutput extends HttpOutput
}
}
+ public boolean mightCompress()
+ {
+ return _state.get()==GZState.MIGHT_COMPRESS;
+ }
public void mightCompress(GzipFactory factory)
{
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
index 3c1f5d8912..0d0e5cf79e 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/GzipFilterContentLengthTest.java
@@ -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);
}
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutCompleteWrite.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutCompleteWrite.java
index a9a3811818..197f140b64 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutCompleteWrite.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/AsyncTimeoutCompleteWrite.java
@@ -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);

Back to the top