Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


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

gorillamania opened this Issue · 1 comment

2 participants



It's accepted practice that when you support compression, Vary: Accept-Encoding http header is sent. From:

"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:

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


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).

@bdarnell bdarnell closed this issue from a commit
@bdarnell bdarnell Return a Vary: Accept-Encoding header whenever gzip is enabled.
This is one of two problems found with redbot.  The other,
that etags should change when content-encoding is used, is trickier to
fix and seems to be less problematic.

Closes #578.
@bdarnell bdarnell closed this in 69ead02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.