fix brotli responses being double-compressed #166
Merged
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.
Related to fastify/fastify-static#158
When used with fastify-static's
preCompressed
option, this plugin will double-compress.br
files.Currently this plugin avoids double-compressing for gzip and deflate, by inspecting the magic number in few bytes of the stream. However Brotli doesn't have a magic number to look for.
fastify-compress/index.js
Lines 491 to 494 in 714e4a9
fastify-compress/index.js
Lines 460 to 465 in 714e4a9
Instead we can check for an existing
Content-Encoding
header on the reply. This has the extra advantage that we don't need to strip off theContent-Length
header.Checklist
npm run test
andnpm run benchmark
and the Code of conduct