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.
Motivation
Requests issued via the
sendBeacon
function have immutable headers. Any header but for the known headers will be ignored. This also means that thex-msw-intention: passthrough
request header set by thebypass()
function will be ignored, causing the infinite loop when bypassing an interceptedsendBeacon
request.Changes
Move the
x-msw-intention: passthrough
toaccept: msw/passthrough
. Theaccept
header is always preserved, and it should be safe to rely on it to provision bypassed requests identification.Also fixes the issue where the request bypass header was preserved for passthrough requests in Node.js only.