Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using compression, Vary: Accept-Encoding should be added #578

Closed
TechNickAI opened this issue Aug 6, 2012 · 1 comment
Closed

When using compression, Vary: Accept-Encoding should be added #578

TechNickAI opened this issue Aug 6, 2012 · 1 comment

Comments

@TechNickAI
Copy link

Hi,

It's accepted practice that when you support compression, Vary: Accept-Encoding http header is sent. From:
https://developers.google.com/speed/docs/best-practices/caching

"Set the Vary: Accept-Encoding response header. This instructs the proxies to cache two versions of the resource: one compressed, and one uncompressed. The correct version of the resource is delivered based on the client request header. This is a good choice for applications that are singly homed and depend on public proxies for user locality."

Apache does this:
http://httpd.apache.org/docs/2.2/mod/mod_deflate.html#proxies

The functionality can be enabled with the following patch:

*************** class GZipContentEncoding(OutputTransfor
*** 1670,1675 ****
--- 1670,1676 ----
("Content-Encoding" not in headers)
if self._gzipping:
headers["Content-Encoding"] = "gzip"

  •         headers["Vary"] = "Accept-Encoding"
          self._gzip_value = BytesIO()
          self._gzip_file = gzip.GzipFile(mode="w", fileobj=self._gzip_value)
          chunk = self.transform_chunk(chunk, finishing)
    

I'm using tornado==2.2

@bdarnell
Copy link
Member

It's a little more complicated than that, for two reasons. First, the Vary header accepts multiple values, so you need to account for the fact that the handler may have added another Vary header (and output transforms don't currently get access to list_headers). Second, the Vary: Accept-Encoding must be sent whether or not the current response is gzipped, if it could have been gzipped (so it needs to be conditioned on the Content-Type being in the allowed list, but not this requests's Accept-Encoding header).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants