Updated Branches: refs/heads/5.3 7912c9971 -> cc5a1098e
TAP5-1880: Disable GZip compression for HTTP/1.0 Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/cc5a1098 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/cc5a1098 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/cc5a1098 Branch: refs/heads/5.3 Commit: cc5a1098ed71b912c1b69dd7e57fbcefc14db185 Parents: 7912c99 Author: Howard M. Lewis Ship <[email protected]> Authored: Mon Jun 11 10:13:36 2012 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Mon Jun 11 10:21:06 2012 -0700 ---------------------------------------------------------------------- build.gradle | 2 +- .../services/ResponseCompressionAnalyzerImpl.java | 23 ++++++++++--- .../services/ResponseCompressionAnalyzer.java | 16 ++++---- .../ResponseCompressionAnalyzerTest.groovy | 26 +++++++++++++++ 4 files changed, 53 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cc5a1098/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index 6b002e8..c83793c 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ project.ext.versions = [ tapestry: "5.3.4-rc-6", jetty: "7.0.0.v20091005", tomcat: "6.0.30", - testng: "5.14.9", + testng: "6.5.2", easymock: "3.0", servletapi: "2.5", spock: "0.6-groovy-1.8" http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cc5a1098/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerImpl.java index 678a139..3e1ac6f 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerImpl.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2009, 2010 The Apache Software Foundation +// Copyright 2009, 2010, 2012 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ package org.apache.tapestry5.internal.services; -import java.util.Collection; - -import javax.servlet.http.HttpServletRequest; - import org.apache.tapestry5.SymbolConstants; import org.apache.tapestry5.internal.TapestryInternalUtils; import org.apache.tapestry5.ioc.annotations.Symbol; import org.apache.tapestry5.services.ResponseCompressionAnalyzer; import org.apache.tapestry5.services.assets.CompressionAnalyzer; +import javax.servlet.http.HttpServletRequest; +import java.util.Collection; + public class ResponseCompressionAnalyzerImpl implements ResponseCompressionAnalyzer { private final HttpServletRequest request; @@ -32,6 +31,8 @@ public class ResponseCompressionAnalyzerImpl implements ResponseCompressionAnaly private final CompressionAnalyzer analyzer; + // configuration is left here for partial compatibility with end-user modules that contribute a value; they + // should contribute to CompressionAnalyzer instead. public ResponseCompressionAnalyzerImpl(HttpServletRequest request, CompressionAnalyzer analyzer, @Deprecated Collection<String> configuration, @Symbol(SymbolConstants.GZIP_COMPRESSION_ENABLED) boolean gzipCompressionEnabled) @@ -44,17 +45,29 @@ public class ResponseCompressionAnalyzerImpl implements ResponseCompressionAnaly public boolean isGZipSupported() { if (!gzipCompressionEnabled) + { return false; + } + + // TAP5-1880: + if (request.getProtocol() == "HTTP/1.0") + { + return false; + } String supportedEncodings = request.getHeader("Accept-Encoding"); if (supportedEncodings == null) + { return false; + } for (String encoding : TapestryInternalUtils.splitAtCommas(supportedEncodings)) { if (encoding.equalsIgnoreCase("gzip")) + { return true; + } } return false; http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cc5a1098/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java index 407e55e..fdc43a8 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/ResponseCompressionAnalyzer.java @@ -1,4 +1,4 @@ -// Copyright 2009, 2011 The Apache Software Foundation +// Copyright 2009, 2011, 2012 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,20 +14,20 @@ package org.apache.tapestry5.services; -import org.apache.tapestry5.ioc.annotations.UsesConfiguration; import org.apache.tapestry5.services.assets.CompressionAnalyzer; /** * Used to determine if the client supports GZIP compression of the response. - * + * + * @see ResponseCompressionAnalyzer * @since 5.1.0.0 */ -@UsesConfiguration(String.class) public interface ResponseCompressionAnalyzer { /** - * Checks the Accept-Encoding request header for a "gzip" token. - * + * Checks the Accept-Encoding request header for a "gzip" token. Ensures that the protocol is not "HTTP/1.0", which + * does not correctly support GZip encoding (in older Internet Explorer browsers). + * * @return true if gzip is supported by client */ boolean isGZipSupported(); @@ -37,9 +37,9 @@ public interface ResponseCompressionAnalyzer * through a GZip filter consumes cycles and makes them larger. * <p/> * Contribute content type strings to the service's configuration to mark them as not compressable. - * + * * @param contentType - * the mime type of the content, such as "text/html" or "image/jpeg". + * the mime type of the content, such as "text/html" or "image/jpeg". * @return true if compression is worthwhile * @deprecated Deprecated in Tapestry 5.3. This method is to be removed at a later date. The service's configuration * is no longer used. Instead, contribute to and use {@link CompressionAnalyzer}. http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cc5a1098/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy new file mode 100644 index 0000000..dcc9998 --- /dev/null +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ResponseCompressionAnalyzerTest.groovy @@ -0,0 +1,26 @@ +package org.apache.tapestry5.internal.services + +import org.apache.tapestry5.ioc.test.TestBase +import org.apache.tapestry5.services.ResponseCompressionAnalyzer +import org.testng.annotations.Test + +import javax.servlet.http.HttpServletRequest + +class ResponseCompressionAnalyzerTest extends TestBase { + + @Test + void "HTTP/1.0 protocol disables gzip compression"() { + + HttpServletRequest request = newMock(HttpServletRequest) + + expect(request.getProtocol()).andReturn("HTTP/1.0").once() + + replay() + + ResponseCompressionAnalyzer rca = new ResponseCompressionAnalyzerImpl(request, null, null, true) + + assert rca.isGZipSupported() == false + + verify() + } +}
