-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix double compression issue when enable_compression() is called on pre-encoded responses #10974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #10974 +/- ##
==========================================
+ Coverage 98.10% 98.76% +0.66%
==========================================
Files 129 129
Lines 39541 39555 +14
Branches 2185 2186 +1
==========================================
+ Hits 38792 39068 +276
+ Misses 591 339 -252
+ Partials 158 148 -10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #10974 will not alter performanceComparing Summary
|
Backport to 3.12: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 9c6da05 on top of patchback/backports/3.12/9c6da05b4233f07d41dd60bf68b8f7a4fe425d9b/pr-10974 Backporting merged PR #10974 into master
🤖 @patchback |
Summary
This PR fixes a flaky test failure caused by double compression when
enable_compression()
is called on responses that already have a Content-Encoding header (e.g., FileResponse serving pre-compressed files).What's Changed
StreamResponse.enable_compression()
to check for existing Content-Encoding header before enabling compressionProblem
The test
test_static_file_with_encoding_and_enable_compression
was failing intermittently with:This occurred when:
file.txt.gz
) and set_compression = False
with appropriate Content-Encoding headerresp.enable_compression(forced_compression)
which unconditionally set_compression = True
Solution
The fix is minimal and backwards-compatible:
enable_compression()
now returns early if Content-Encoding header is already presentWhy This Approach?
Testing
test_enable_compression_with_existing_encoding
to verify the fix