mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #33735 -- Added async support to StreamingHttpResponse.
Thanks to Florian Vazelle for initial exploratory work, and to Nick Pope and Mariusz Felisiak for review.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user