Author: markt
Date: Wed Nov  3 18:54:56 2010
New Revision: 1030610

URL: http://svn.apache.org/viewvc?rev=1030610&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49625
Ensure Vary header is set if response may be compressed rather than only 
setting it if it is compressed.

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1030610&r1=1030609&r2=1030610&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Wed Nov  3 18:54:56 2010
@@ -102,14 +102,6 @@ PATCHES PROPOSED TO BACKPORT:
    but from debugging it looks that it is called by Tomcat code only
    (JspServlet).
 
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49625
-  Ensure Vary header is set if response may be compressed rather than only
-  setting it if it is compressed.
-  http://svn.apache.org/viewvc?rev=1002133&view=rev
-  (patch needs to be applied separately to BIO, NIO and APR HTTP connectors)
-  +1: markt, mturk, kkolinko
-  -1:
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49730
   Correct race condition in StandardThreadExecutor that can lead to long delays
   in processing requests. Patch provided by Sylvain Laurent.

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=1030610&r1=1030609&r2=1030610&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 
Wed Nov  3 18:54:56 2010
@@ -1520,16 +1520,42 @@ public class Http11AprProcessor implemen
 
 
     /**
-     * Check for compression
+     * Check if the resource could be compressed, if the client supports it.
      */
     private boolean isCompressable() {
 
-        // Nope Compression could works in HTTP 1.0 also
-        // cf: mod_deflate
+        // Check if content is not already gzipped
+        MessageBytes contentEncodingMB =
+            response.getMimeHeaders().getValue("Content-Encoding");
+
+        if ((contentEncodingMB != null)
+            && (contentEncodingMB.indexOf("gzip") != -1))
+            return false;
+
+        // If force mode, always compress (test purposes only)
+        if (compressionLevel == 2)
+           return true;
+
+        // Check if sufficient length to trigger the compression
+        long contentLength = response.getContentLengthLong();
+        if ((contentLength == -1)
+            || (contentLength > compressionMinSize)) {
+            // Check for compatible MIME-TYPE
+            if (compressableMimeTypes != null) {
+                return (startsWithStringArray(compressableMimeTypes,
+                                              response.getContentType()));
+            }
+        }
+
+        return false;
+    }
 
-        // Compression only since HTTP 1.1
-        // if (! http11)
-        //    return false;
+
+    /**
+     * Check if compression should be used for this resource. Already checked
+     * that the resource could be compressed if the client supports it.
+     */
+    private boolean useCompression() {
 
         // Check if browser support gzip encoding
         MessageBytes acceptEncodingMB =
@@ -1539,15 +1565,7 @@ public class Http11AprProcessor implemen
             || (acceptEncodingMB.indexOf("gzip") == -1))
             return false;
 
-        // Check if content is not allready gzipped
-        MessageBytes contentEncodingMB =
-            response.getMimeHeaders().getValue("Content-Encoding");
-
-        if ((contentEncodingMB != null)
-            && (contentEncodingMB.indexOf("gzip") != -1))
-            return false;
-
-        // If force mode, allways compress (test purposes only)
+        // If force mode, always compress (test purposes only)
         if (compressionLevel == 2)
            return true;
 
@@ -1565,21 +1583,10 @@ public class Http11AprProcessor implemen
             }
         }
 
-        // Check if suffisant len to trig the compression
-        long contentLength = response.getContentLengthLong();
-        if ((contentLength == -1)
-            || (contentLength > compressionMinSize)) {
-            // Check for compatible MIME-TYPE
-            if (compressableMimeTypes != null) {
-                return (startsWithStringArray(compressableMimeTypes,
-                                              response.getContentType()));
-            }
-        }
-
-        return false;
+        return true;
     }
 
-
+    
     /**
      * When committing the response, we have to validate the set of headers, as
      * well as setup the response filters.
@@ -1634,9 +1641,13 @@ public class Http11AprProcessor implemen
         }
         
         // Check for compression
+        boolean isCompressable = false;
         boolean useCompression = false;
         if (entityBody && (compressionLevel > 0) && (sendfileData == null)) {
-            useCompression = isCompressable();
+            isCompressable = isCompressable();
+            if (isCompressable) {
+                useCompression = useCompression();
+            }
             // Change content-length to -1 to force chunking
             if (useCompression) {
                 response.setContentLength(-1);
@@ -1679,6 +1690,9 @@ public class Http11AprProcessor implemen
         if (useCompression) {
             outputBuffer.addActiveFilter(outputFilters[Constants.GZIP_FILTER]);
             headers.setValue("Content-Encoding").setString("gzip");
+        }
+        // If it might be compressed, set the Vary header
+        if (isCompressable) {
             // Make Proxies happy via Vary (from mod_deflate)
             MessageBytes vary = headers.getValue("Vary");
             if (vary == null) {

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1030610&r1=1030609&r2=1030610&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
Wed Nov  3 18:54:56 2010
@@ -1549,16 +1549,42 @@ public class Http11NioProcessor implemen
 
 
     /**
-     * Check for compression
+     * Check if the resource could be compressed, if the client supports it.
      */
     private boolean isCompressable() {
 
-        // Nope Compression could works in HTTP 1.0 also
-        // cf: mod_deflate
+        // Check if content is not already gzipped
+        MessageBytes contentEncodingMB =
+            response.getMimeHeaders().getValue("Content-Encoding");
+
+        if ((contentEncodingMB != null)
+            && (contentEncodingMB.indexOf("gzip") != -1))
+            return false;
+
+        // If force mode, always compress (test purposes only)
+        if (compressionLevel == 2)
+           return true;
+
+        // Check if sufficient length to trigger the compression
+        long contentLength = response.getContentLengthLong();
+        if ((contentLength == -1)
+            || (contentLength > compressionMinSize)) {
+            // Check for compatible MIME-TYPE
+            if (compressableMimeTypes != null) {
+                return (startsWithStringArray(compressableMimeTypes,
+                                              response.getContentType()));
+            }
+        }
+
+        return false;
+    }
 
-        // Compression only since HTTP 1.1
-        // if (! http11)
-        //    return false;
+
+    /**
+     * Check if compression should be used for this resource. Already checked
+     * that the resource could be compressed if the client supports it.
+     */
+    private boolean useCompression() {
 
         // Check if browser support gzip encoding
         MessageBytes acceptEncodingMB =
@@ -1568,15 +1594,7 @@ public class Http11NioProcessor implemen
             || (acceptEncodingMB.indexOf("gzip") == -1))
             return false;
 
-        // Check if content is not allready gzipped
-        MessageBytes contentEncodingMB =
-            response.getMimeHeaders().getValue("Content-Encoding");
-
-        if ((contentEncodingMB != null)
-            && (contentEncodingMB.indexOf("gzip") != -1))
-            return false;
-
-        // If force mode, allways compress (test purposes only)
+        // If force mode, always compress (test purposes only)
         if (compressionLevel == 2)
            return true;
 
@@ -1594,21 +1612,10 @@ public class Http11NioProcessor implemen
             }
         }
 
-        // Check if suffisant len to trig the compression
-        long contentLength = response.getContentLengthLong();
-        if ((contentLength == -1)
-            || (contentLength > compressionMinSize)) {
-            // Check for compatible MIME-TYPE
-            if (compressableMimeTypes != null) {
-                return (startsWithStringArray(compressableMimeTypes,
-                                              response.getContentType()));
-            }
-        }
-
-        return false;
+        return true;
     }
 
-
+    
     /**
      * When committing the response, we have to validate the set of headers, as
      * well as setup the response filters.
@@ -1662,9 +1669,13 @@ public class Http11NioProcessor implemen
 
 
         // Check for compression
+        boolean isCompressable = false;
         boolean useCompression = false;
         if (entityBody && (compressionLevel > 0) && (sendfileData == null)) {
-            useCompression = isCompressable();
+            isCompressable = isCompressable();
+            if (isCompressable) {
+                useCompression = useCompression();
+            }
             // Change content-length to -1 to force chunking
             if (useCompression) {
                 response.setContentLength(-1);
@@ -1707,6 +1718,9 @@ public class Http11NioProcessor implemen
         if (useCompression) {
             outputBuffer.addActiveFilter(outputFilters[Constants.GZIP_FILTER]);
             headers.setValue("Content-Encoding").setString("gzip");
+        }
+        // If it might be compressed, set the Vary header
+        if (isCompressable) {
             // Make Proxies happy via Vary (from mod_deflate)
             MessageBytes vary = headers.getValue("Vary");
             if (vary == null) {

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1030610&r1=1030609&r2=1030610&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java Wed 
Nov  3 18:54:56 2010
@@ -1431,16 +1431,42 @@ public class Http11Processor implements 
 
 
     /**
-     * Check for compression
+     * Check if the resource could be compressed, if the client supports it.
      */
     private boolean isCompressable() {
 
-        // Nope Compression could works in HTTP 1.0 also
-        // cf: mod_deflate
+        // Check if content is not already gzipped
+        MessageBytes contentEncodingMB =
+            response.getMimeHeaders().getValue("Content-Encoding");
+
+        if ((contentEncodingMB != null)
+            && (contentEncodingMB.indexOf("gzip") != -1))
+            return false;
+
+        // If force mode, always compress (test purposes only)
+        if (compressionLevel == 2)
+           return true;
+
+        // Check if sufficient length to trigger the compression
+        long contentLength = response.getContentLengthLong();
+        if ((contentLength == -1)
+            || (contentLength > compressionMinSize)) {
+            // Check for compatible MIME-TYPE
+            if (compressableMimeTypes != null) {
+                return (startsWithStringArray(compressableMimeTypes,
+                                              response.getContentType()));
+            }
+        }
+
+        return false;
+    }
+
 
-        // Compression only since HTTP 1.1
-        // if (! http11)
-        //    return false;
+    /**
+     * Check if compression should be used for this resource. Already checked
+     * that the resource could be compressed if the client supports it.
+     */
+    private boolean useCompression() {
 
         // Check if browser support gzip encoding
         MessageBytes acceptEncodingMB =
@@ -1450,15 +1476,7 @@ public class Http11Processor implements 
             || (acceptEncodingMB.indexOf("gzip") == -1))
             return false;
 
-        // Check if content is not allready gzipped
-        MessageBytes contentEncodingMB =
-            response.getMimeHeaders().getValue("Content-Encoding");
-
-        if ((contentEncodingMB != null)
-            && (contentEncodingMB.indexOf("gzip") != -1))
-            return false;
-
-        // If force mode, allways compress (test purposes only)
+        // If force mode, always compress (test purposes only)
         if (compressionLevel == 2)
            return true;
 
@@ -1476,21 +1494,10 @@ public class Http11Processor implements 
             }
         }
 
-        // Check if suffisant len to trig the compression
-        long contentLength = response.getContentLengthLong();
-        if ((contentLength == -1)
-            || (contentLength > compressionMinSize)) {
-            // Check for compatible MIME-TYPE
-            if (compressableMimeTypes != null) {
-                return (startsWithStringArray(compressableMimeTypes,
-                                              response.getContentType()));
-            }
-        }
-
-        return false;
+        return true;
     }
 
-
+    
     /**
      * When committing the response, we have to validate the set of headers, as
      * well as setup the response filters.
@@ -1528,10 +1535,13 @@ public class Http11Processor implements 
         }
 
         // Check for compression
+        boolean isCompressable = false;
         boolean useCompression = false;
         if (entityBody && (compressionLevel > 0)) {
-            useCompression = isCompressable();
-
+            isCompressable = isCompressable();
+            if (isCompressable) {
+                useCompression = useCompression();
+            }
             // Change content-length to -1 to force chunking
             if (useCompression) {
                 response.setContentLength(-1);
@@ -1574,6 +1584,9 @@ public class Http11Processor implements 
         if (useCompression) {
             outputBuffer.addActiveFilter(outputFilters[Constants.GZIP_FILTER]);
             headers.setValue("Content-Encoding").setString("gzip");
+        }
+        // If it might be compressed, set the Vary header
+        if (isCompressable) {
             // Make Proxies happy via Vary (from mod_deflate)
             MessageBytes vary = headers.getValue("Vary");
             if (vary == null) {



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

Reply via email to