mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
561 stars 126 forks source link

Should not set readable if statusCode is 204 #433

Closed mikicho closed 1 year ago

mikicho commented 1 year ago

https://github.com/mswjs/interceptors/blob/main/src/interceptors/ClientRequest/utils/createResponse.ts#L21

image

mikicho commented 1 year ago

Also for 101, 103, 204, 205, or 304. https://fetch.spec.whatwg.org/#statuses

kettanaito commented 1 year ago

I've opened a fix for this in #436. @mikicho, note that while status codes 101 and 103 also forbid response from having a body, you cannot even construct responses with those status codes. The ResponseInit.status expects a [200, 599] status code range.

new Response(null, { status: 101 })
// Uncaught RangeError: Failed to construct 'Response': The status provided (101) is outside the range [200, 599].

The library won't account for those status codes because it's unnecessary.

kettanaito commented 1 year ago

Released: v0.25.3 🎉

This has been released in v0.25.3!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.