interceptors
interceptors copied to clipboard
fix(fetch): support `Content-Encoding` response header
- Fixes #446
- Related to #575
Added failing test.
@kettanaito
- At first, I thought to adopt Nock's implementation (inspired by undici), but IIRC,
interceptors
is cross-platform and AFAIKzlib
does not exist in the browser. How does the browser decompress the response body? Am I missing something? - From what I see,
IncomingMessage
does not decompress the response body, and Node.js leaves this for the HTTP libraries (Axios, got, etc.). So, I think we should follow this behavior and leave the response body compressed.
Summary
- We are not reusing Undici's decompression logic directly because that'd mean redistributing Undici alongside Interceptors.
- We are using Compression Streams API to decompress GZIP and Deflate both in Node.js and the browser.
- We are using
zlib
and a custom transform stream to support Brotli decompression in Node.js. - We are ignoring Brotli in the browser due to WASM issues.