fix(decompress): stop inflating compress and x-compress - #5665
fix(decompress): stop inflating compress and x-compress#5665luantaraschi wants to merge 1 commit into
Conversation
RFC 9110 section 8.4.1.1 defines compress as the UNIX compress (LZW) format, not zlib, so createInflate cannot read it. A compress-encoded response failed with Z_DATA_ERROR instead of being passed through. fetch() in this repo already handles only x-gzip, gzip, deflate, br and zstd and leaves everything else alone. The two codings now take that same path, and the docs are updated to match.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5665 +/- ##
=======================================
Coverage 93.43% 93.44%
=======================================
Files 110 110
Lines 38733 38778 +45
=======================================
+ Hits 36190 36235 +45
Misses 2543 2543 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Quick note on the one red job here, in case it is what is holding this up. The failure is This branch only touches The branch is 6 commits behind |
This relates to...
No open issue. Found while reading
lib/interceptor/decompress.js.Rationale
supportedEncodingsmapscompressandx-compresstocreateInflate:Those are different formats. RFC 9110 section 8.4.1.1 defines
compressas the UNIX compress (LZW) format, whiledeflateis zlib. Node has no LZW decoder, so feeding acompressbody to inflate cannot succeed. It does not degrade, it fails the request:fetch()does not do this. Its coding switch inlib/web/fetch/index.jshandlesx-gzip,gzip,deflate,brandzstd, and anything else falls through untouched. Same response, same server, both from this repo:So composing the decompress interceptor onto a client turns a response that
fetchreads fine into a hard failure.The two entries are removed.
compressandx-compressnow take the path every other unrecognised coding already takes:#createDecompressionChainreturns an empty chain, the body passes through, andContent-Encodingstays on the response since nothing was decoded. The only case this changes is a server that labels zlib data ascompress, which is already mislabelled and whichfetchnever decoded either.The doc line that advertised the two codings is updated to match.
Worth noting: this touches the same file as #5664, but a different region, so the two apply independently.
Changes
compressandx-compressremoved fromsupportedEncodings, with a comment recording why.docs/docs/api/Interceptors.md: the decompress section no longer lists the two codings and says unrecognised codings are left untouched.Test added to
test/interceptors/decompress.js: aContent-Encoding: compressresponse with a non-inflatable body arrives unchanged instead of erroring.Features
N/A
Bug Fixes
A
Content-Encoding: compressresponse no longer fails withZ_DATA_ERRORunder the decompress interceptor.Breaking Changes and Deprecations
A server sending zlib data labelled
compresswas being decoded and now is not. That labelling is already wrong per RFC 9110, andfetch()in this repo has never decoded it.Status