Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Nov 10, 2024

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Nov 10, 2024

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 kettanaito changed the title fix(bypass): support sendBeacon() requests fix: prevent infinite loop when bypassing sendBeacon() requests Nov 10, 2024
@kettanaito kettanaito merged commit 2fa98c3 into main Nov 10, 2024
11 checks passed
@kettanaito kettanaito deleted the fix/bypass-keepalive-requests branch November 10, 2024 21:07
@kettanaito
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sendBeacon causes infinite loop with response patching
1 participant