tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1835264 - in /tomcat/trunk: java/org/apache/catalina/filters/CorsFilter.java java/org/apache/catalina/servlets/DefaultServlet.java java/org/apache/coyote/CompressionConfig.java webapps/docs/changelog.xml
Date Fri, 06 Jul 2018 16:25:41 GMT
Author: markt
Date: Fri Jul  6 16:25:40 2018
New Revision: 1835264

URL: http://svn.apache.org/viewvc?rev=1835264&view=rev
Log:
Refactor code that adds an additional header name to the Vary HTTP response header to use
a common utility method that addresses several additional edge cases.

Modified:
    tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java
    tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
    tomcat/trunk/java/org/apache/coyote/CompressionConfig.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java?rev=1835264&r1=1835263&r2=1835264&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java Fri Jul  6 16:25:40 2018
@@ -39,6 +39,7 @@ import javax.servlet.http.HttpServletRes
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.http.ResponseUtil;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -290,8 +291,7 @@ public class CorsFilter extends GenericF
         }
 
         // Indicate the response depends on the origin
-        response.addHeader(CorsFilter.REQUEST_HEADER_VARY,
-                CorsFilter.REQUEST_HEADER_ORIGIN);
+        ResponseUtil.addVaryFieldName(response, CorsFilter.REQUEST_HEADER_ORIGIN);
 
         // Forward the request down the filter chain.
         filterChain.doFilter(request, response);
@@ -976,7 +976,10 @@ public class CorsFilter extends GenericF
     /**
      * The Vary header indicates allows disabling proxy caching by indicating
      * the the response depends on the origin.
+     *
+     * @deprecated Unused. Will be removed in Tomcat 10
      */
+    @Deprecated
     public static final String REQUEST_HEADER_VARY = "Vary";
 
     /**

Modified: tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java?rev=1835264&r1=1835263&r2=1835264&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java Fri Jul  6 16:25:40
2018
@@ -37,7 +37,6 @@ import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.security.AccessController;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
@@ -75,6 +74,7 @@ import org.apache.catalina.connector.Res
 import org.apache.catalina.util.ServerInfo;
 import org.apache.catalina.util.URLEncoder;
 import org.apache.tomcat.util.buf.B2CConverter;
+import org.apache.tomcat.util.http.ResponseUtil;
 import org.apache.tomcat.util.res.StringManager;
 import org.apache.tomcat.util.security.Escape;
 import org.apache.tomcat.util.security.PrivilegedGetTccl;
@@ -868,18 +868,7 @@ public class DefaultServlet extends Http
             List<PrecompressedResource> precompressedResources =
                     getAvailablePrecompressedResources(path);
             if (!precompressedResources.isEmpty()) {
-                Collection<String> varyHeaders = response.getHeaders("Vary");
-                boolean addRequired = true;
-                for (String varyHeader : varyHeaders) {
-                    if ("*".equals(varyHeader) ||
-                            "accept-encoding".equalsIgnoreCase(varyHeader)) {
-                        addRequired = false;
-                        break;
-                    }
-                }
-                if (addRequired) {
-                    response.addHeader("Vary", "accept-encoding");
-                }
+                ResponseUtil.addVaryFieldName(response, "accept-encoding");
                 PrecompressedResource bestResource =
                         getBestPrecompressedResource(request, precompressedResources);
                 if (bestResource != null) {

Modified: tomcat/trunk/java/org/apache/coyote/CompressionConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/CompressionConfig.java?rev=1835264&r1=1835263&r2=1835264&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/CompressionConfig.java (original)
+++ tomcat/trunk/java/org/apache/coyote/CompressionConfig.java Fri Jul  6 16:25:40 2018
@@ -23,6 +23,7 @@ import java.util.regex.Pattern;
 
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.MimeHeaders;
+import org.apache.tomcat.util.http.ResponseUtil;
 
 public class CompressionConfig {
 
@@ -212,17 +213,7 @@ public class CompressionConfig {
 
         // If processing reaches this far, the response might be compressed.
         // Therefore, set the Vary header to keep proxies happy
-        MessageBytes vary = responseHeaders.getValue("Vary");
-        if (vary == null) {
-            // Add a new Vary header
-            responseHeaders.setValue("Vary").setString("Accept-Encoding");
-        } else if (vary.equals("*")) {
-            // No action required
-        } else {
-            // Merge into current header
-            responseHeaders.setValue("Vary").setString(vary.getString() + ",Accept-Encoding");
-        }
-
+        ResponseUtil.addVaryFieldName(responseHeaders, "accept-encoding");
 
         // Check if browser support gzip encoding
         MessageBytes acceptEncodingMB = request.getMimeHeaders().getValue("accept-encoding");

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1835264&r1=1835263&r2=1835264&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Jul  6 16:25:40 2018
@@ -83,6 +83,11 @@
         <bug>62507</bug>: Ensure that JSSE based TLS connectors work correctly
         with a DKS keystore. (markt)
       </fix>
+      <fix>
+        Refactor code that adds an additional header name to the
+        <code>Vary</code> HTTP response header to use a common utility method
+        that addresses several additional edge cases. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">



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


Mime
View raw message