interceptors icon indicating copy to clipboard operation
interceptors copied to clipboard

fix(fetch): support `Content-Encoding` response header

Open mikicho opened this issue 7 months ago • 27 comments

  • Fixes #446
  • Related to #575

Added failing test.

@kettanaito

  1. At first, I thought to adopt Nock's implementation (inspired by undici), but IIRC, interceptors is cross-platform and AFAIK zlib does not exist in the browser. How does the browser decompress the response body? Am I missing something?
  2. 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.

mikicho avatar Jul 12 '24 19:07 mikicho