diff options
| author | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-01-28 21:43:23 +0000 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-02-03 18:19:06 +0100 |
| commit | d88c24f436ae23ff5aec4ea06c0c27499a71e074 (patch) | |
| tree | 75025815afd5f392ba93b8c9a91b99fdf5e1c944 /django/http | |
| parent | 43b0131fb5724cb92716eedfe35a6b2b4d84e1e5 (diff) | |
[1.8.x] Fixed #24240 -- Allowed GZipping a Unicode StreamingHttpResponse
make_bytes() assumed that if the Content-Encoding header is set, then
everything had already been dealt with bytes-wise, but in a streaming
situation this was not necessarily the case.
make_bytes() is only called when necessary when working with a
StreamingHttpResponse iterable, but by that point the middleware has
added the Content-Encoding header and thus make_bytes() tried to call
bytes(value) (and dies). If it had been a normal HttpResponse,
make_bytes() would have been called when the content was set, well
before the middleware set the Content-Encoding header.
This commit removes the special casing when Content-Encoding is set,
allowing unicode strings to be encoded during the iteration before they
are e.g. gzipped. This behaviour was added a long time ago for #4969 and
it doesn't appear to be necessary any more, as everything is correctly
made into bytes at the appropriate places.
Two new tests, to show that supplying non-ASCII characters to a
StreamingHttpResponse works fine normally, and when passed through the
GZip middleware (the latter dies without the change to make_bytes()).
Removes the test with a nonsense Content-Encoding and Unicode input - if
this were to happen, it can still be encoded as bytes fine.
Backport of 250aa7c39b from master.
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/response.py | 4 |
1 files changed, 0 insertions, 4 deletions
diff --git a/django/http/response.py b/django/http/response.py index 560e2ac7a5..eedd6c2c72 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -282,10 +282,6 @@ class HttpResponseBase(six.Iterator): # an instance of a subclass, this function returns `bytes(value)`. # This doesn't make a copy when `value` already contains bytes. - # If content is already encoded (eg. gzip), assume bytes. - if self.has_header('Content-Encoding'): - return bytes(value) - # Handle string types -- we can't rely on force_bytes here because: # - under Python 3 it attempts str conversion first # - when self._charset != 'utf-8' it re-encodes the content |
