tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [tomcat] branch 7.0.x updated: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63932 ETag & gzip
Date Thu, 28 Nov 2019 16:33:35 GMT
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/7.0.x by this push:
     new aad9939  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63932 ETag & gzip
aad9939 is described below

commit aad993909f254539e38b9aca6e9be505437c4a43
Author: Mark Thomas <markt@apache.org>
AuthorDate: Thu Nov 28 16:33:16 2019 +0000

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63932 ETag & gzip
    
    By default, do not compress content that has a strong ETag. This
    behaviour is configuration for the HTTP/1.1 and HTTP/2 connectors via
    the new Connector attribute noCompressionStrongETag
---
 .../coyote/http11/AbstractHttp11Processor.java     | 27 ++++++++++++++++++++--
 .../coyote/http11/AbstractHttp11Protocol.java      | 10 ++++++++
 .../apache/coyote/http11/Http11AprProtocol.java    |  4 ++--
 .../apache/coyote/http11/Http11NioProtocol.java    |  4 ++--
 java/org/apache/coyote/http11/Http11Protocol.java  |  4 ++--
 webapps/docs/changelog.xml                         | 10 ++++++++
 webapps/docs/config/http.xml                       |  8 +++++++
 7 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/coyote/http11/AbstractHttp11Processor.java b/java/org/apache/coyote/http11/AbstractHttp11Processor.java
index 288b4ed..787d388 100644
--- a/java/org/apache/coyote/http11/AbstractHttp11Processor.java
+++ b/java/org/apache/coyote/http11/AbstractHttp11Processor.java
@@ -216,6 +216,12 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S>
{
 
 
     /**
+     * Flag to disable compression when the resource has a strong ETag.
+     */
+    protected boolean noCompressionStrongETag = true;
+
+
+    /**
      * Minimum content size to make compression.
      */
     protected int compressionMinSize = 2048;
@@ -334,6 +340,11 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S>
{
     }
 
 
+    public void setNoCompressionStrongETag(boolean noCompressionStrongETag) {
+        this.noCompressionStrongETag = noCompressionStrongETag;
+    }
+
+
     /**
      * Set no compression user agent pattern. Regular expression as supported
      * by {@link Pattern}.
@@ -607,15 +618,17 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S>
{
      */
     private boolean isCompressible() {
 
+        MimeHeaders responseHeaders = response.getMimeHeaders();
+
         // Check if content is not already compressed
-        MessageBytes contentEncodingMB = response.getMimeHeaders().getValue("Content-Encoding");
+        MessageBytes contentEncodingMB = responseHeaders.getValue("Content-Encoding");
 
         if (contentEncodingMB != null) {
             // Content-Encoding values are ordered but order is not important
             // for this check so use a Set rather than a List
             Set<String> tokens = new HashSet<String>();
             try {
-                TokenList.parseTokenList(response.getMimeHeaders().values("Content-Encoding"),
tokens);
+                TokenList.parseTokenList(responseHeaders.values("Content-Encoding"), tokens);
             } catch (IOException e) {
                 // Because we are using StringReader, any exception here is a
                 // Tomcat bug.
@@ -627,6 +640,16 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S>
{
             }
         }
 
+        // Check if the resource has a strong ETag
+        if (noCompressionStrongETag) {
+            String eTag = responseHeaders.getHeader("ETag");
+            if (eTag != null && !eTag.trim().startsWith("W/")) {
+                // Has an ETag that doesn't start with "W/..." so it must be a
+                // strong ETag
+                return false;
+            }
+        }
+
         // If force mode, always compress (test purposes only)
         if (compressionLevel == 2) {
             return true;
diff --git a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
index 334116d..1993fcc 100644
--- a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
+++ b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
@@ -203,6 +203,15 @@ public abstract class AbstractHttp11Protocol<S> extends AbstractProtocol<S>
{
     }
 
 
+    private boolean noCompressionStrongETag = true;
+    public boolean getNoCompressionStrongETag() {
+        return noCompressionStrongETag;
+    }
+    public void setNoCompressionStrongEtag(boolean noCompressionStrongETag) {
+        this.noCompressionStrongETag = noCompressionStrongETag;
+    }
+
+
     /**
      * Regular expression that defines the User agents which should be
      * restricted to HTTP/1.0 support.
@@ -362,6 +371,7 @@ public abstract class AbstractHttp11Protocol<S> extends AbstractProtocol<S>
{
         processor.setConnectionUploadTimeout(getConnectionUploadTimeout());
         processor.setDisableUploadTimeout(getDisableUploadTimeout());
         processor.setCompressionMinSize(getCompressionMinSize());
+        processor.setNoCompressionStrongETag(getNoCompressionStrongETag());
         processor.setCompression(getCompression());
         processor.setNoCompressionUserAgents(getNoCompressionUserAgents());
         processor.setCompressibleMimeTypes(getCompressibleMimeType());
diff --git a/java/org/apache/coyote/http11/Http11AprProtocol.java b/java/org/apache/coyote/http11/Http11AprProtocol.java
index f16ee13..a5495d8 100644
--- a/java/org/apache/coyote/http11/Http11AprProtocol.java
+++ b/java/org/apache/coyote/http11/Http11AprProtocol.java
@@ -307,10 +307,10 @@ public class Http11AprProtocol extends AbstractHttp11Protocol<Long>
{
             processor.setAdapter(proto.adapter);
             processor.setMaxKeepAliveRequests(proto.getMaxKeepAliveRequests());
             processor.setKeepAliveTimeout(proto.getKeepAliveTimeout());
-            processor.setConnectionUploadTimeout(
-                    proto.getConnectionUploadTimeout());
+            processor.setConnectionUploadTimeout(proto.getConnectionUploadTimeout());
             processor.setDisableUploadTimeout(proto.getDisableUploadTimeout());
             processor.setCompressionMinSize(proto.getCompressionMinSize());
+            processor.setNoCompressionStrongETag(proto.getNoCompressionStrongETag());
             processor.setCompression(proto.getCompression());
             processor.setNoCompressionUserAgents(proto.getNoCompressionUserAgents());
             processor.setCompressableMimeTypes(proto.getCompressableMimeTypes());
diff --git a/java/org/apache/coyote/http11/Http11NioProtocol.java b/java/org/apache/coyote/http11/Http11NioProtocol.java
index d313bc1..fa51a3b 100644
--- a/java/org/apache/coyote/http11/Http11NioProtocol.java
+++ b/java/org/apache/coyote/http11/Http11NioProtocol.java
@@ -272,10 +272,10 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol<NioChannel>
{
             processor.setAdapter(proto.adapter);
             processor.setMaxKeepAliveRequests(proto.getMaxKeepAliveRequests());
             processor.setKeepAliveTimeout(proto.getKeepAliveTimeout());
-            processor.setConnectionUploadTimeout(
-                    proto.getConnectionUploadTimeout());
+            processor.setConnectionUploadTimeout(proto.getConnectionUploadTimeout());
             processor.setDisableUploadTimeout(proto.getDisableUploadTimeout());
             processor.setCompressionMinSize(proto.getCompressionMinSize());
+            processor.setNoCompressionStrongETag(proto.getNoCompressionStrongETag());
             processor.setCompression(proto.getCompression());
             processor.setNoCompressionUserAgents(proto.getNoCompressionUserAgents());
             processor.setCompressableMimeTypes(proto.getCompressableMimeTypes());
diff --git a/java/org/apache/coyote/http11/Http11Protocol.java b/java/org/apache/coyote/http11/Http11Protocol.java
index 16a4b40..54a2ee3 100644
--- a/java/org/apache/coyote/http11/Http11Protocol.java
+++ b/java/org/apache/coyote/http11/Http11Protocol.java
@@ -171,10 +171,10 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol<Socket>
{
             processor.setAdapter(proto.adapter);
             processor.setMaxKeepAliveRequests(proto.getMaxKeepAliveRequests());
             processor.setKeepAliveTimeout(proto.getKeepAliveTimeout());
-            processor.setConnectionUploadTimeout(
-                    proto.getConnectionUploadTimeout());
+            processor.setConnectionUploadTimeout(proto.getConnectionUploadTimeout());
             processor.setDisableUploadTimeout(proto.getDisableUploadTimeout());
             processor.setCompressionMinSize(proto.getCompressionMinSize());
+            processor.setNoCompressionStrongETag(proto.getNoCompressionStrongETag());
             processor.setCompression(proto.getCompression());
             processor.setNoCompressionUserAgents(proto.getNoCompressionUserAgents());
             processor.setCompressableMimeTypes(proto.getCompressableMimeTypes());
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index fbc5504..9aa33be 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -74,6 +74,16 @@
       </add>
     </changelog>
   </subsection>
+  <subsection name="Coyote">
+    <changelog>
+       <fix>
+        <bug>63932</bug>: By default, do not compress content that has a strong
+        ETag. This behaviour is configuration for the HTTP/1.1 connectors via
+        the new Connector attribute <code>noCompressionStrongETag</code>.
+        (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Other">
     <changelog>
       <fix>
diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml
index 4327bd3..de72702 100644
--- a/webapps/docs/config/http.xml
+++ b/webapps/docs/config/http.xml
@@ -502,6 +502,14 @@
       used.</p>
     </attribute>
 
+    <attribute name="noCompressionStrongETag" required="false">
+      <p>This flag configures whether resources with a stong ETag will be
+      considered for compression. If <code>true</code>, resources with a strong
+      ETag will not be compressed. The default value is <code>true</code>.</p>
+      <p>This attribute is deprecated. It will be removed in Tomcat 10 onwards
+      where it will be hard-coded to <code>true</code>.</p>
+    </attribute>
+
     <attribute name="noCompressionUserAgents" required="false">
       <p>The value is a regular expression (using <code>java.util.regex</code>)
       matching the <code>user-agent</code> header of HTTP clients for which


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message