summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Richter <richter.benjamin@gmail.com>2015-01-25 23:22:46 +0100
committerTim Graham <timograham@gmail.com>2015-01-26 19:22:47 -0500
commit1e39d0f6280abf34c7719db5e7ed1c333f5e5919 (patch)
treeda2dedc80c43585cbbf25ef183290b44b93c04c0 /tests
parent9435474068c2ae2261105adbbe7aebdb80b778f3 (diff)
[1.4.x] Fixed #24158 -- Allowed GZipMiddleware to work with streaming responses
Backport of django.utils.text.compress_sequence and fix for django.middleware.gzip.GZipMiddleware when using iterators as response.content.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/middleware/tests.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py
index 138ee50e43..87b19fb6da 100644
--- a/tests/regressiontests/middleware/tests.py
+++ b/tests/regressiontests/middleware/tests.py
@@ -514,6 +514,7 @@ class GZipMiddlewareTest(TestCase):
short_string = "This string is too short to be worth compressing."
compressible_string = 'a' * 500
uncompressible_string = ''.join(chr(random.randint(0, 255)) for _ in xrange(500))
+ iterator_as_content = iter(compressible_string)
def setUp(self):
self.req = HttpRequest()
@@ -589,6 +590,18 @@ class GZipMiddlewareTest(TestCase):
self.assertEqual(r.content, self.uncompressible_string)
self.assertEqual(r.get('Content-Encoding'), None)
+ def test_streaming_compression(self):
+ """
+ Tests that iterators as response content return a compressed stream without consuming
+ the whole response.content while doing so.
+ See #24158.
+ """
+ self.resp.content = self.iterator_as_content
+ r = GZipMiddleware().process_response(self.req, self.resp)
+ self.assertEqual(self.decompress(''.join(r.content)), self.compressible_string)
+ self.assertEqual(r.get('Content-Encoding'), 'gzip')
+ self.assertEqual(r.get('Content-Length'), None)
+
class ETagGZipMiddlewareTest(TestCase):
"""