summaryrefslogtreecommitdiff
path: root/cherrypy/lib/encoding.py
diff options
context:
space:
mode:
authorjaraco <none@none>2009-03-30 22:44:05 +0000
committerjaraco <none@none>2009-03-30 22:44:05 +0000
commit11d8e939f92440fa89f6923b7afcd8fb5e01a2f9 (patch)
tree64f9c5bd247b528a0a9ebdcf368df653743359ab /cherrypy/lib/encoding.py
parent9a4e9cea5332c011b147c84ddf1dc5f17f44715f (diff)
downloadcherrypy-git-11d8e939f92440fa89f6923b7afcd8fb5e01a2f9.tar.gz
Now add the vary header in gzip regardless of whether gzip actually compresses something
Diffstat (limited to 'cherrypy/lib/encoding.py')
-rw-r--r--cherrypy/lib/encoding.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py
index fe2ca74d..410a2dca 100644
--- a/cherrypy/lib/encoding.py
+++ b/cherrypy/lib/encoding.py
@@ -221,6 +221,9 @@ def gzip(compress_level=5, mime_types=['text/html', 'text/plain']):
* The 'identity' value is given with a qvalue > 0.
"""
response = cherrypy.response
+
+ set_vary_header(response, "Accept-Encoding")
+
if not response.body:
# Response body is empty (might be a 304 for instance)
return
@@ -249,8 +252,7 @@ def gzip(compress_level=5, mime_types=['text/html', 'text/plain']):
if coding.qvalue == 0:
return
if ct in mime_types:
- set_vary_header(response)
-
+ # Return a generator that compresses the page
response.headers['Content-Encoding'] = 'gzip'
response.body = compress(response.body, compress_level)
if response.headers.has_key("Content-Length"):
@@ -259,10 +261,9 @@ def gzip(compress_level=5, mime_types=['text/html', 'text/plain']):
return
cherrypy.HTTPError(406, "identity, gzip").set_response()
-def set_vary_header(response):
- # Return a generator that compresses the page
+def set_vary_header(response, header_name):
varies = response.headers.get("Vary", "")
varies = [x.strip() for x in varies.split(",") if x.strip()]
- if "Accept-Encoding" not in varies:
- varies.append("Accept-Encoding")
+ if header_name not in varies:
+ varies.append(header_name)
response.headers['Vary'] = ", ".join(varies)