diff options
author | Robert Brewer <fumanchu@aminus.org> | 2006-10-20 07:14:06 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2006-10-20 07:14:06 +0000 |
commit | b20c6f68995fbf9fb182e64a928dd0266fa815c5 (patch) | |
tree | a3f8be3b76f6bd2b7a64c9760ebec63e6b62418e /cherrypy/lib/encoding.py | |
parent | 501c3afbd6b7446be83313c351153095ebd529d1 (diff) | |
download | cherrypy-git-b20c6f68995fbf9fb182e64a928dd0266fa815c5.tar.gz |
Trunk fix for #577 (GzipFilter doesn't force an update of the Content-Length header). All code which could change the length of response.body should delete the Content-Length header (if already set).
Diffstat (limited to 'cherrypy/lib/encoding.py')
-rw-r--r-- | cherrypy/lib/encoding.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py index 82a1d081..14391880 100644 --- a/cherrypy/lib/encoding.py +++ b/cherrypy/lib/encoding.py @@ -100,6 +100,18 @@ def find_acceptable_charset(encoding=None, default_encoding='utf-8', errors='str else: response.collapse_body() encoder = encode_string + if response.headers.has_key("Content-Length"): + # Delete Content-Length header so finalize() recalcs it. + # Encoded strings may be of different lengths from their + # unicode equivalents, and even from each other. For example: + # >>> t = u"\u7007\u3040" + # >>> len(t) + # 2 + # >>> len(t.encode("UTF-8")) + # 6 + # >>> len(t.encode("utf7")) + # 8 + del response.headers["Content-Length"] # Parse the Accept-Charset request header, and try to provide one # of the requested charsets (in order of user preference). @@ -217,5 +229,8 @@ def gzip(compress_level=9, mime_types=['text/html', 'text/plain']): response.headers['Content-Encoding'] = 'gzip' response.body = compress(response.body, compress_level) + if response.headers.has_key("Content-Length"): + # Delete Content-Length header so finalize() recalcs it. + del response.headers["Content-Length"] return cherrypy.HTTPError(406, "identity, gzip").set_response() |