diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-05-21 01:26:35 -0700 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-05-21 01:26:35 -0700 |
| commit | 18856f866cc0e1cc703ae3f4c84b3c25a847b370 (patch) | |
| tree | 67661f18c8be92816fab948e9c08d42e002515b2 /tests/http_utils | |
| parent | e24d486fbc0b1c42abe8b54217ff428e449c48cc (diff) | |
| parent | 0594fed9ffd6cf6e10475488934cb02d9263829e (diff) | |
Merge pull request #1191 from ambv/content_is_bytes
Fixed #20472: response.content should be bytes on both Python 2 and 3
Diffstat (limited to 'tests/http_utils')
| -rw-r--r-- | tests/http_utils/tests.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/http_utils/tests.py b/tests/http_utils/tests.py index 7dfd24d721..06a310a787 100644 --- a/tests/http_utils/tests.py +++ b/tests/http_utils/tests.py @@ -1,10 +1,21 @@ from __future__ import unicode_literals +import io +import gzip + from django.http import HttpRequest, HttpResponse, StreamingHttpResponse from django.http.utils import conditional_content_removal from django.test import TestCase +# based on Python 3.3's gzip.compress +def gzip_compress(data): + buf = io.BytesIO() + with gzip.GzipFile(fileobj=buf, mode='wb', compresslevel=0) as f: + f.write(data) + return buf.getvalue() + + class HttpUtilTests(TestCase): def test_conditional_content_removal(self): @@ -33,6 +44,19 @@ class HttpUtilTests(TestCase): conditional_content_removal(req, res) self.assertEqual(b''.join(res), b'') + # Issue #20472 + abc = gzip_compress(b'abc') + res = HttpResponse(abc, status=304) + res['Content-Encoding'] = 'gzip' + conditional_content_removal(req, res) + self.assertEqual(res.content, b'') + + res = StreamingHttpResponse([abc], status=304) + res['Content-Encoding'] = 'gzip' + conditional_content_removal(req, res) + self.assertEqual(b''.join(res), b'') + + # Strip content for HEAD requests. req.method = 'HEAD' |
