fix(compress): skip compression for 206 and Content-Range responses#5023
Open
naveentehrpariya wants to merge 1 commit into
Open
fix(compress): skip compression for 206 and Content-Range responses#5023naveentehrpariya wants to merge 1 commit into
naveentehrpariya wants to merge 1 commit into
Conversation
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses item 2 of #5010.
compress()skips onContent-Encoding/Transfer-Encoding/ HEAD / threshold / type /no-transform, but not on partial/range responses. A206 Partial Content(or any response carryingContent-Range) gets gzipped while itsContent-Rangeheader still describes the uncompressed byte range — so a range client reassembling the stream gets corrupted data. nginx and apache skip compression on range responses for exactly this reason.Reproduction (before this PR)
Fix
Add two guards to the existing skip condition:
Content-Rangeis checked in addition to the206status because it can also appear on a200response, and either way the header would no longer match the compressed bytes.Tests
Added a
Range Responsessuite asserting a206response and aContent-Rangeresponse are both passed through uncompressed with theirContent-Range/Content-Lengthintact. Both fail without this change and pass with it; the full compress suite (39 tests) passes,tsc --noEmitand eslint are clean.The author should do the following, if applicable
bun run format:fix && bun run lint:fixto format the code