summaryrefslogtreecommitdiff
path: root/tests/middleware
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2022-12-13 16:15:25 +0100
committerCarlton Gibson <carlton.gibson@noumenal.es>2022-12-22 10:41:12 +0100
commit0bd2c0c9015b53c41394a1c0989afbfd94dc2830 (patch)
tree6b24758335cf10eeedfdf7dec50cda3500796305 /tests/middleware
parentae0899be0d787fbfc5f5ab2b18c5a8219d822d2b (diff)
Fixed #33735 -- Added async support to StreamingHttpResponse.
Thanks to Florian Vazelle for initial exploratory work, and to Nick Pope and Mariusz Felisiak for review.
Diffstat (limited to 'tests/middleware')
-rw-r--r--tests/middleware/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py
index 1b8efe1a3e..e29d32ad74 100644
--- a/tests/middleware/tests.py
+++ b/tests/middleware/tests.py
@@ -899,6 +899,28 @@ class GZipMiddlewareTest(SimpleTestCase):
self.assertEqual(r.get("Content-Encoding"), "gzip")
self.assertFalse(r.has_header("Content-Length"))
+ async def test_compress_async_streaming_response(self):
+ """
+ Compression is performed on responses with async streaming content.
+ """
+
+ async def get_stream_response(request):
+ async def iterator():
+ for chunk in self.sequence:
+ yield chunk
+
+ resp = StreamingHttpResponse(iterator())
+ resp["Content-Type"] = "text/html; charset=UTF-8"
+ return resp
+
+ r = await GZipMiddleware(get_stream_response)(self.req)
+ self.assertEqual(
+ self.decompress(b"".join([chunk async for chunk in r])),
+ b"".join(self.sequence),
+ )
+ self.assertEqual(r.get("Content-Encoding"), "gzip")
+ self.assertFalse(r.has_header("Content-Length"))
+
def test_compress_streaming_response_unicode(self):
"""
Compression is performed on responses with streaming Unicode content.