diff options
| author | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-12-13 16:15:25 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-12-22 10:41:12 +0100 |
| commit | 0bd2c0c9015b53c41394a1c0989afbfd94dc2830 (patch) | |
| tree | 6b24758335cf10eeedfdf7dec50cda3500796305 /tests/middleware | |
| parent | ae0899be0d787fbfc5f5ab2b18c5a8219d822d2b (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.py | 22 |
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. |
