Cannot disable redirects with `maxRedirects: 0`
See original GitHub issueDescribe the bug
I’m using axios to send a login request to an old back-end that always returns a 302 no matter it being successful or not. I don’t want to actually follow the redirect that server is suggesting (as the front-end is being rewritten from scratch and the location is non-existant). And also, I’m required to have the headers that the server is returning with the 302 response.
In short: I don’t want the redirects to be followed and I want to process the original 302 response.
To Reproduce
This works as expected in nodejs (and therefore on runkit), but it does not work in a browser. (For the following code to work, I had to load axios in https://httpstat.us/ and run the code in the console to prevent CORS errors.)
await axios.request({
method: "GET",
url: "https://httpstat.us/302",
maxRedirects: 0,
validateStatus: null,
});
The returned response in the browser is the redirected response with status code 200.
Expected behavior
No redirects are followed in the browser (like in nodejs, and as described in the documentation), and the response status code returned is 302.
Environment
- Axios Version 0.21.1 (latest)
- Adapter I don’t know.
- Browser Firefox
- Browser Version 90.0.2 (latest)
- Node.js Version N/A
- OS: Windows 10 Build 19043.928
- Additional Library Versions N/A
Additional context/Screenshots
-–
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
The max Redirects default value should be 0. I’ve been trying to pull Status Code 302 for 2 days. Today I saw that the default value is 5. It was always returning 200 code.
@Shayan-To I don’t think it’s bug because in req_config doc, it mentions that maxRedirects works only in nodeJS.