Skip to content
This repository was archived by the owner on Aug 18, 2022. It is now read-only.

Conversation

ivanph
Copy link

@ivanph ivanph commented May 5, 2017

Matches the behavior of request:
https://github.com/request/request/blob/b12a6245/lib/redirect.js#L134-L138

Fixes #1

A few cases are missing from the tests but I wasn't sure if I should create a new server just for that and I dunno if I should test all redirect status codes for this case.

I wasn't sure if this had to be handled in that piece of code you pointed to, cause that only seems to cover POST requests and from the request code it seems that they do it for all methods but HEAD

Copy link

@zkat zkat left a comment

Choose a reason for hiding this comment

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

This looks great so far! Thanks so much for picking it up! I made a comment regarding some corner cases with the Location header, but things otherwise look fine 🎉

src/index.js Outdated
// Remove authorization if changing hostnames (but not if just
// changing ports or protocols). This matches the behavior of request:
// https://github.com/request/request/blob/b12a6245/lib/redirect.js#L134-L138
if (url.parse(request.url).hostname !== url.parse(res.headers.location).hostname) {
Copy link

Choose a reason for hiding this comment

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

I think we need to emulate request's behavior a little more closely here: res.headers.location can be /foo or foo.com/x, which would not have a hostname property when put through url.parse().

It might be nicer to have code that's more explicit about detecting these different cases, instead of using request's concise but not-very-explicit implementation of it.

This patch looks otherwise fine, and I'm mostly fine with the tests as they are, modulo adding tests for Location: /foo and Location: foo.com and such

Copy link

Choose a reason for hiding this comment

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

Correction!

The Location header accepts a URI-Reference. That is, either a relative ref, or a fully-qualified URI (with ports). www.foo.com is invalid. I kinda wonder if anyone sends it that way, though.

Copy link

@zkat zkat May 5, 2017

Choose a reason for hiding this comment

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

Correction again: It allows protocol-relative URIs (that is, //foo.com/bar). So that still needs to be compensated for. Heh.

Copy link
Author

Choose a reason for hiding this comment

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

I think I solved the issues with parsing different types of urls and also added a couple more test cases. I wasn't sure about URIs like foo.com cause it seems those are not valid but maybe I'm misreading. Lemme know if there is anymore changes I should make.

@ivanph
Copy link
Author

ivanph commented May 5, 2017

Thanks!! I'll try to make this changes ASAP

Copy link

@zkat zkat left a comment

Choose a reason for hiding this comment

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

LGTM! Great work :D

@ivanph
Copy link
Author

ivanph commented May 7, 2017

Awesome!!
Thanks for all the great work you've been doing on npm

troger added a commit to nuxeo/nuxeo-js-client that referenced this pull request May 21, 2018
It allows us to benefit from some security fix such as
npm/node-fetch-npm#2
troger added a commit to nuxeo/nuxeo-js-client that referenced this pull request May 22, 2018
It allows us to benefit from some security fix such as
npm/node-fetch-npm#2
troger added a commit to nuxeo/nuxeo-js-client that referenced this pull request May 22, 2018
It allows us to benefit from some security fix such as
npm/node-fetch-npm#2
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants