question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot disable redirects with `maxRedirects: 0`

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
alpgulcommented, Sep 23, 2021

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.

1reaction
iyorozuyacommented, Sep 2, 2021

@Shayan-To I don’t think it’s bug because in req_config doc, it mentions that maxRedirects works only in nodeJS.

  // `maxRedirects` defines the maximum number of redirects to follow in node.js.
  // If set to 0, no redirects will be followed.
  maxRedirects: 5, // default
Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable axios redirects in react-native
With that the case, I did try setting maxRedirects: 0 or redirect: 'manual' (See code example) Is there a way to not get...
Read more >
How to Fix The ERR_TOO_MANY_REDIRECTS Error
This error happens when the browser can't establish a connection between the initial page and the destination page in a redirect. The main...
Read more >
follow redirect
No, you have to disable redirects (.redirects().follow(false)) and then create a filter that looks at the location header and stores the response somewhere...
Read more >
Do not follow HTTP redirects with Gaxios - Technical Notes
My attempt to adjust maxRedirects value to 1 along with keeping status validation in place was not successful either – gaxios just issued ......
Read more >
unwanted redirect after updating to 96.0.3 | Firefox ...
This has never happened before the new update and I can't figure out how to stop it. There is no longer an "Options"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found