From bb4fcf5f67e6a39440bb1271450319604a755f2e Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Oct 2025 00:10:35 +0100 Subject: [6.0.x] Fixed #36656 -- Avoided truncating async streaming responses in GZipMiddleware. Backport of a0323a0c44135c28134672e6e633e5f4a7a68d5d from main. --- tests/middleware/tests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py index c4aac0552b..a61c4b147f 100644 --- a/tests/middleware/tests.py +++ b/tests/middleware/tests.py @@ -2,6 +2,7 @@ import gzip import random import re import struct +import zlib from io import BytesIO from unittest import mock from urllib.parse import quote @@ -880,8 +881,8 @@ class GZipMiddlewareTest(SimpleTestCase): @staticmethod def decompress(gzipped_string): - with gzip.GzipFile(mode="rb", fileobj=BytesIO(gzipped_string)) as f: - return f.read() + # Use zlib to ensure gzipped_string contains exactly one gzip stream. + return zlib.decompress(gzipped_string, zlib.MAX_WBITS | 16) @staticmethod def get_mtime(gzipped_string): -- cgit v1.3