mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
15.97k stars 519 forks source link

Request by got + compression hangs forever #2200

Closed tim-coulter closed 3 months ago

tim-coulter commented 4 months ago

Prerequisites

Environment check

Node.js version

v22.3.0

Reproduction repository

https://github.com/tim-coulter/msw-got-compression-example

Reproduction steps

npm i npm run server npm run test

Note that this is only reproducible with the following:

Current behavior

When the msw server has not started listening both the got and fetch requests work as expected and return a response. When the mock server is started, however, only the fetch request returns a response but the request using got appears to hang (got works 2 is never seen).

Expected behavior

As that request is not being intercepted by msw the behaviour should be exactly the same as before starting the server as after (the request made using got should not hang).

kettanaito commented 3 months ago

Hi, @tim-coulter. Thanks for reporting this.

We are working on improving the handling of encoded response bodies in Node.js, and hope to merge the fix in the nearest future. One of such improvements is making Undici expose their encoding utilities (see https://github.com/nodejs/undici/pull/3423) and then forwarding that usage to Interceptors (see https://github.com/mswjs/interceptors/pull/604). Once these two are merged, MSW should handle compressed response bodies correctly in Node.js.