Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49570
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 10 Jul 2010 17:20:41 +0000 (17:20 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 10 Jul 2010 17:20:41 +0000 (17:20 +0000)
When using the example compression filter, set the Vary header on compressed responses

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@962889 13f79535-47bb-0310-9956-ffa450edef68

webapps/docs/changelog.xml
webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java

index 605330e..042b1b4 100644 (file)
         naming resources that broke the complete server status page in the
         manager application. Note these MBeans now have a new name. (markt)
       </fix>
+      <fix>
+        <bug>49570</bug>: When using the example compression filter, set the
+        Vary header on compressed responses. (markt)
+      </fix>
     </changelog>
   </subsection>
 </section>
index 4a65b4f..6aff0c2 100644 (file)
@@ -306,6 +306,16 @@ public class CompressionResponseStream
                 gzipstream = output;
             } else {
                 response.addHeader("Content-Encoding", "gzip");
+                String vary = response.getHeader("Vary");
+                if (vary == null) {
+                    // Add a new Vary header
+                    response.setHeader("Vary", "Accept-Encoding");
+                } else if (vary.equals("*")) {
+                    // No action required
+                } else {
+                    // Merge into current header
+                    response.setHeader("Vary", vary + ",Accept-Encoding");
+                }
                 gzipstream = new GZIPOutputStream(output);
             }
         }