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

Adding support for beforeRedirect config option #3852

Merged
merged 11 commits into from Mar 7, 2022

Conversation

zoran995
Copy link
Contributor

@zoran995 zoran995 commented Jun 24, 2021

Axios for long time supports following of the redirects using the follow-redirects package, but it didn't implemented support for beforeRedirect function which is useful to easily control the redirects.
This adds support for providing the beforeRedirect function in options.
Also updated the maxRedirects default value in readme, it is 21 for around 5 years.

@@ -273,7 +276,7 @@ module.exports = function httpAdapter(config) {

// Handle errors
req.on('error', function handleRequestError(err) {
if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') return;
if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') reject(err);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this request will never complete.

Copy link
Contributor Author

@zoran995 zoran995 Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to expand more on this change, I haven't used enhanceError since this should be an error thrown from client application so we return it as is.
It's a bit strange that no one before run into the issue of stuck request

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
zoran995 and others added 2 commits August 18, 2021 21:04
Co-authored-by: Prabodh Meshram <prabodh.meshram7@gmail.com>
@jasonsaayman
Copy link
Member

@zoran995 can you please fix the merge conflicts?

@zoran995
Copy link
Contributor Author

@jasonsaayman merge conflicts are resolved

@zoran995
Copy link
Contributor Author

zoran995 commented Jan 20, 2022

@jasonsaayman it seems that something weird was going on on my end, typescript never complained about those issues and all tests passed successfully (it started to complain yesterday). Those are totally valid ts errors, which should have been thrown from the start
Probably the best solution is to type beforeRedirect parameters as any and add details in the doc about correct types

beforeRedirect?: (options: any, responseDetails: {headers: any}) => void; 

any other ideas?

@zoran995
Copy link
Contributor Author

zoran995 commented Feb 7, 2022

@jasonsaayman I have resolved type issues, both are now typed as records(objects)

@jasonsaayman jasonsaayman merged commit 412d3bd into axios:master Mar 7, 2022
@zoran995 zoran995 deleted the redirect-options branch March 15, 2022 15:38
@@ -227,6 +227,9 @@ module.exports = function httpAdapter(config) {
if (config.maxRedirects) {
options.maxRedirects = config.maxRedirects;
}
if (config.beforeRedirect) {
options.beforeRedirect = config.beforeRedirect;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this break proxy support when redirection occurs?

The setProxy function, which is called before hitting this line, sets options.beforeRedirect to re-apply proxy configuration after a redirect. This line here happily stamps over it.

Either there should be something to harmonize the two features (such as registering a function that invokes both the original config beforeRedirect if needed, and the proxy re-configuration next) or the documentation should state that the config.beforeRedirect option is incompatible with proxy support (😿) and can introduce proxy redirect issues.

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.

None yet

4 participants