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

Maintain specified headers for redirects #7

Merged
merged 2 commits into from
Jan 19, 2016
Merged

Maintain specified headers for redirects #7

merged 2 commits into from
Jan 19, 2016

Conversation

ctate
Copy link
Contributor

@ctate ctate commented Jan 15, 2016

Hey @ForbesLindesay - I ran into #4 with this code:

request('GET', 'https://api.github.com/repos/isaacs/npm', {followRedirects: true, headers: {'User-Agent': 'http-basic'}}, function (err, res) {
  if (err) throw err;
  console.log(res.statusCode); // error 403
});

This PR fixes the issue by maintaining all original headers through redirects except for "content-length" in GET requests (which should also help with the other issue mentioned in the comment). I also added a little test.

Let me know if this works or if you'd like it to work differently. Thanks!

@ForbesLindesay
Copy link
Owner

I think we should explicitly copy over a short list of headers. Perhaps even specify a default list and allow the user to extend that list. The issue is that if I send an auth header to a trusted website, but it redirects me to a malicious website by accident, I might then expose my credentials. Not sure the best API here.

@ctate ctate reopened this Jan 18, 2016
@ctate
Copy link
Contributor Author

ctate commented Jan 18, 2016

That works for me. I just need User-Agent for GitHub. Updated PR.

@ctate ctate changed the title Maintain (most) original headers Maintain User-Agent header Jan 18, 2016
@ctate
Copy link
Contributor Author

ctate commented Jan 18, 2016

Actually - updated to add the option allowRedirectHeaders so it's flexible and better for backwards compatibility.

@ctate ctate changed the title Maintain User-Agent header Maintain specified headers for redirects Jan 18, 2016
ForbesLindesay added a commit that referenced this pull request Jan 19, 2016
Maintain specified headers for redirects
@ForbesLindesay ForbesLindesay merged commit 3cbdf04 into ForbesLindesay:master Jan 19, 2016
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.

2 participants