-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Invalid redirect in pipe #1471
Invalid redirect in pipe #1471
Conversation
test/node/pipe.js
Outdated
@@ -92,4 +100,48 @@ describe("request pipe", () => { | |||
}); | |||
req.pipe(stream); | |||
}); | |||
|
|||
it("should follow redirects", done => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a test for pipes with a good redirect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize now there is already a test for a good redirect in ./test/node/pipe-redirect.js
test/node/pipe.js
Outdated
req.pipe(stream); | ||
}); | ||
|
||
it("should not throw on bad redirects", done => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a test to prove that redirects with a missing Location will not throw and error.
package-lock.json | ||
*.swp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added *.swp
to the gitignore for vim files
Edit: Tests now passing in Travis for all node versions 6, 8, 10, and 11. |
lib/node/index.js
Outdated
if (redirect && this._redirects++ != this._maxRedirects) { | ||
if (!res.headers.location) { | ||
this.callback(new Error('No location header for redirect'), res); | ||
stream.end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, superagent should not be responsible for ending the client stream if there is an error. Instead the client should listen for the error
event and then handle their stream on their own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please advise...
@louisbuchbinder could you please refactor/pull latest from master? may be easiest to start fresh. would love to get this added to v5.x release that just came out. |
@niftylettuce I rebased and update for the linting rules |
@louisbuchbinder v5.0.4 is released, thank you |
There is a bug in redirects during a pipe. If the request responds with a redirect status, but an empty Location header then superagent will throw
Uncaught TypeError: Cannot read property '_pipeContinue' of undefined
.To reproduce you can checkout my tests (without the patch) and run them. You will see:
or you can reproduce with by hand with something like: