Closed a11rew closed 2 months ago
Hi, @a11rew. Thanks for reporting this.
We have a test for follow-redirects
here but, apparently, it misses something. One difference I can spot is that in our tests the original server responds with a redirect, while in your use case the mock does that. Perhaps that's the culprit.
Would you have some time to add a new test case to the test I've linked above? Something like
interceptor.on('request', ({ request }) => {
request.respondWith(new Response(null, {
status: 300,
headers: { Location: '/new/url' }
}))
})
Added the failing test case in this PR https://github.com/mswjs/interceptors/pull/581 @kettanaito. I'd be open to contributing a fix for this, any pointers on where I should be looking?
Could be potentially fixed by https://github.com/mswjs/interceptors/issues/626. Afaik, Axios uses XHR by default, so we need to look into whether XHR follows redirects to distinguish if that's a request client behavior or Axios' behavior.
This has been released in v2.4.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.
Prerequisites
Environment check
msw
versionNode.js version
v20.12.2
Other versions
msw
- 2.3.1axios
- 1.7.2Reproduction repository
https://codesandbox.io/p/devbox/axios-follow-redirects-issue-9qn7z9
Reproduction steps
new Response
with 3xx code and Location header)Current behavior
The request fails with this error message originating from the
follow-redirects
library Axios usesThe stack trace points to this line in the
follow-redirects
lib https://github.com/follow-redirects/follow-redirects/blob/35a517c5861d79dc8bff7db8626013d20b711b06/index.js#L422response.req.getHeader
is undefined in theIncomingMessage
/response follow-redirects receives when the response is mocked using MSW. This does not happen when the requests returning redirects are not intercepted with MSW.Expected behavior
Axios should be able to follow redirects normally like it does when responses are not mocked with MSW.