Adding redirectLocationTrusted option to retain authorization header on redirect domain change #2876
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist:
npm test
locally and all tests are passing.PR Description
If a redirect location has a different domain than the original request (excluding port and protocol changes) then any authorization header is removed from the request. This is currently a deliberate choice in the code, to do the same as curl (for security reasons), as per this comment: https://github.com/request/request/blob/master/lib/redirect.js#L134
Curl does have an option --location-trusted for overriding that behaviour though: (https://curl.haxx.se/docs/manpage.html#--location-trusted) so this pull request is to add an equivalent option
redirectLocationTrusted
to request. If not supplied this option defaults to false, keeping the original behaviour.In this change I've kept
redirectLocationTrusted
as the simple boolean that curl has. It could be overloaded for finer grained options (e.g. a domain matching regex) if it was felt that would be of more value.