mswjs / msw

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

fix: prevent infinite loop when bypassing `sendBeacon()` requests #2353

Closed kettanaito closed 1 week ago

kettanaito commented 1 week ago

Motivation

Requests issued via the sendBeacon function have immutable headers. Any header but for the known headers will be ignored. This also means that the x-msw-intention: passthrough request header set by the bypass() function will be ignored, causing the infinite loop when bypassing an intercepted sendBeacon request.

Changes

Move the x-msw-intention: passthrough to accept: msw/passthrough. The accept header is always preserved, and it should be safe to rely on it to provision bypassed requests identification.

Note that MSW will remove that msw/passthrough part of the request's accept header before actually performing the request.

Also fixes the issue where the request bypass header was preserved for passthrough requests in Node.js only.

kettanaito commented 1 week ago

Released: v2.6.4 🎉

This has been released in v2.6.4!

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


Predictable release automation by @ossjs/release.