2014-08-04 21:22 GMT+04:00 <ma...@apache.org>: > Author: markt > Date: Mon Aug 4 17:22:01 2014 > New Revision: 1615697 > > URL: http://svn.apache.org/r1615697 > Log: > When the gzip option is enabled for the DefaultServlet ensure that a suitable > Vary header is returned for resources that might be returned directly in > compressed form. > > Modified: > tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java > tomcat/trunk/webapps/docs/changelog.xml > > 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=1615697&r1=1615696&r2=1615697&view=diff > ============================================================================== > --- tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java > (original) > +++ tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java Mon > Aug 4 17:22:01 2014 > @@ -799,16 +799,15 @@ public class DefaultServlet extends Http > > // Serve a gzipped version of the file if present > boolean usingGzippedVersion = false; > - if (gzip && > - resource.isFile() && > - !included &&
1). I do get why "!included" check was moved to the place below. I think it should not be moved. I think that "included" flag does not depend on "accept-encoding" value sent by user. 2). There may already be a Vary header in the response. RFC 7230 Chapter 3.2.2. Field Order [quote] A sender MUST NOT generate multiple header fields with the same field name in a message unless either the entire field value for that header field is defined as a comma-separated list [i.e., #(values)] or the header field is a well-known exception (as noted below). [/quote] The well-known exception referenced above is "Set-Cookie" header. RFC 7231 Chapter 7.1.4. Vary defines the field as Vary = "*" / 1#field-name so it is an alternative between "*" versus a list of values, so the above requirement for allowing multiple headers is not met. 3) The code may check response.isCommitted(). (In other words, that addHeader("Content-Encoding", "gzip") call has been successful). Best regards, Konstantin Kolinko > - !path.endsWith(".gz") && > - checkIfGzip(request)) { > + if (gzip && resource.isFile() && !path.endsWith(".gz")) { > WebResource gzipResource = resources.getResource(path + ".gz"); > if (gzipResource.exists() && gzipResource.isFile()) { > - response.addHeader("Content-Encoding", "gzip"); > - resource = gzipResource; > - usingGzippedVersion = true; > + response.addHeader("Vary", "accept-encoding"); > + if (!included && checkIfGzip(request)) { > + response.addHeader("Content-Encoding", "gzip"); > + resource = gzipResource; > + usingGzippedVersion = true; > + } > } > } > > > Modified: tomcat/trunk/webapps/docs/changelog.xml > URL: > http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1615697&r1=1615696&r2=1615697&view=diff > ============================================================================== > --- tomcat/trunk/webapps/docs/changelog.xml (original) > +++ tomcat/trunk/webapps/docs/changelog.xml Mon Aug 4 17:22:01 2014 > @@ -80,6 +80,12 @@ > and it need not be fatal when the Realm starts. Based on a patch by > Cédric Couralet. (markt) > </fix> > + <fix> > + When the <code>gzip</code> option is enabled for the > + <code>DefaultServlet</code> ensure that a suitable <code>Vary</code> > + header is returned for resources that might be returned directly in > + compressed form. > + </fix> > </changelog> > </subsection> > <subsection name="Coyote"> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org