1
0
mirror of https://github.com/django/django.git synced 2025-03-28 02:00:45 +00:00
Matthew Somerville 250aa7c39b 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.
2015-02-03 18:18:12 +01:00
..
2015-01-20 12:18:03 -05:00
2014-10-22 21:21:02 -04:00
2013-12-24 12:25:17 +01:00
2015-01-20 12:18:03 -05:00
2015-01-28 07:00:52 -05:00
2014-08-18 13:44:10 -04:00
2015-01-20 12:18:03 -05:00
2013-11-02 23:50:49 -05:00
2014-12-06 12:06:06 -05:00
2015-01-20 12:18:03 -05:00
2013-12-24 12:25:17 +01:00
2015-01-20 12:18:03 -05:00
2015-01-27 22:39:57 +07:00
2013-02-26 10:00:14 +01:00

To run the test suite::

    $ cd tests
    $ pip install -r requirements/py3.txt  # or py2.txt
    $ PYTHONPATH=..:$PYTHONPATH ./runtests.py

For more information about the test suite, see
https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/.