fix: skip compression for 206 and Content-Range responses#402
Merged
mcollina merged 1 commit intoJun 14, 2026
Merged
Conversation
A 206 Partial Content response carries a Content-Range header whose
byte offsets refer to the original, unencoded payload. Compressing the
body invalidates those offsets, producing data that range clients
cannot safely reassemble.
Add two guards to the noCompress check:
- reply.statusCode === 206
- reply.getHeader('Content-Range') !== undefined
Mirrors the fix applied to @hono/compress (#5023) and the pending PR
against expressjs/compression (fastify#277).
climba03003
approved these changes
Jun 13, 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.
Summary
A
206 Partial Contentresponse carries aContent-Rangeheader whose byte offsets describe the original, unencoded payload. When@fastify/compresscompresses such a response, the body shrinks butContent-Rangestill describes the pre-compression byte range — a range client stitching parts together gets corrupted data.The same class of bug was recently fixed in
hono/compress(honojs/hono#5023) and is tracked inexpressjs/compression(#277).Changes
index.js— two new guards in thenoCompresscheck:test/global-compress.test.js— newRange Responsesdescribe block with two tests:it should not compress 206 Partial Content responsesit should not compress responses carrying a Content-Range headerTest
Checklist
npm test→ 0 failures)