Author: markt
Date: Tue Sep 28 12:08:53 2010
New Revision: 1002133

URL: http://svn.apache.org/viewvc?rev=1002133&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/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1002133&r1=1002132&r2=1002133&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java Tue 
Sep 28 12:08:53 2010
@@ -640,16 +640,42 @@ public abstract class AbstractHttp11Proc
 
 
     /**
-     * Check for compression
+     * Check if the resource could be compressed, if the client supports it.
      */
-    protected boolean isCompressable() {
+    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()));
+            }
+        }
 
-        // Compression only since HTTP 1.1
-        // if (! http11)
-        //    return false;
+        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 =
@@ -659,14 +685,6 @@ public abstract class AbstractHttp11Proc
             || (acceptEncodingMB.indexOf("gzip") == -1))
             return false;
 
-        // 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;
@@ -685,18 +703,7 @@ public abstract class AbstractHttp11Proc
             }
         }
 
-        // 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;
+        return true;
     }
 
     
@@ -973,9 +980,13 @@ public abstract class AbstractHttp11Proc
         }
         
         // Check for compression
+        boolean isCompressable = false;
         boolean useCompression = false;
         if (entityBody && (compressionLevel > 0) && !sendingWithSendfile) {
-            useCompression = isCompressable();
+            isCompressable = isCompressable();
+            if (isCompressable) {
+                useCompression = useCompression();
+            }
             // Change content-length to -1 to force chunking
             if (useCompression) {
                 response.setContentLength(-1);
@@ -1018,6 +1029,9 @@ public abstract class AbstractHttp11Proc
         if (useCompression) {
             
getOutputBuffer().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/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1002133&r1=1002132&r2=1002133&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Sep 28 12:08:53 2010
@@ -188,6 +188,10 @@
         (markt)
       </fix>
       <fix>
+        <bug>49625</bug>: Ensure Vary header is set if response may be
+        compressed rather than only setting it if it is compressed. (markt)
+      </fix>
+      <fix>
         <bug>49802</bug>: Re-factor connector pause, stop and destroy methods 
so
         that calling any of those methods has the expected results. (markt)
       </fix>



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

Reply via email to