diff options
| author | Adam Johnson <me@adamj.eu> | 2025-10-11 00:10:35 +0100 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-10-21 10:45:12 -0400 |
| commit | a0323a0c44135c28134672e6e633e5f4a7a68d5d (patch) | |
| tree | 8897abf89af92589f84c8dfe5f907f37d503b580 /django/middleware/gzip.py | |
| parent | 9bb83925d6c231e964f8b54efbc982fb1333da27 (diff) | |
Fixed #36656 -- Avoided truncating async streaming responses in GZipMiddleware.
Diffstat (limited to 'django/middleware/gzip.py')
| -rw-r--r-- | django/middleware/gzip.py | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/django/middleware/gzip.py b/django/middleware/gzip.py index 7ccd00ac19..eb151d7ad5 100644 --- a/django/middleware/gzip.py +++ b/django/middleware/gzip.py @@ -1,7 +1,7 @@ from django.utils.cache import patch_vary_headers from django.utils.deprecation import MiddlewareMixin from django.utils.regex_helper import _lazy_re_compile -from django.utils.text import compress_sequence, compress_string +from django.utils.text import acompress_sequence, compress_sequence, compress_string re_accepts_gzip = _lazy_re_compile(r"\bgzip\b") @@ -32,18 +32,10 @@ class GZipMiddleware(MiddlewareMixin): if response.streaming: if response.is_async: - # pull to lexical scope to capture fixed reference in case - # streaming_content is set again later. - original_iterator = response.streaming_content - - async def gzip_wrapper(): - async for chunk in original_iterator: - yield compress_string( - chunk, - max_random_bytes=self.max_random_bytes, - ) - - response.streaming_content = gzip_wrapper() + response.streaming_content = acompress_sequence( + response.streaming_content, + max_random_bytes=self.max_random_bytes, + ) else: response.streaming_content = compress_sequence( response.streaming_content, |
