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/utils/text.py | |
| parent | 9bb83925d6c231e964f8b54efbc982fb1333da27 (diff) | |
Fixed #36656 -- Avoided truncating async streaming responses in GZipMiddleware.
Diffstat (limited to 'django/utils/text.py')
| -rw-r--r-- | django/utils/text.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/django/utils/text.py b/django/utils/text.py index 26edde99e3..bad1da6729 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -393,6 +393,22 @@ def compress_sequence(sequence, *, max_random_bytes=None): yield buf.read() +async def acompress_sequence(sequence, *, max_random_bytes=None): + buf = StreamingBuffer() + filename = _get_random_filename(max_random_bytes) if max_random_bytes else None + with GzipFile( + filename=filename, mode="wb", compresslevel=6, fileobj=buf, mtime=0 + ) as zfile: + # Output headers... + yield buf.read() + async for item in sequence: + zfile.write(item) + data = buf.read() + if data: + yield data + yield buf.read() + + # Expression to match some_token and some_token="with spaces" (and similarly # for single-quoted strings). smart_split_re = _lazy_re_compile( |
