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
net: allow controlling redirects #9007
Conversation
cedc2b3
to
6afbda5
Compare
@deepak1556 does this need some user-facing documentation changes? |
@zeke yup, have added the docs. Please take a look, thanks! |
docs/api/client-request.md
Outdated
* `redirect` String (optional) - The redirect mode for this request. Should be | ||
one of `follow`, `error` or `manual`. Defaults to `follow`. When mode is `error`, | ||
any redirection will be aborted. When mode is `manual` the redirection will be | ||
deferred until [`request.followRedirect`](#requestfollowRedirecct) is invoked, listen to [`redirect`](#event-redirect) event in |
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.
requestfollowRedirecct → requestfollowRedirect
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.
invoked, listen to → invoked. Listen for the
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.
Fixed, thanks!
0ccd159
to
b551f51
Compare
@arantes555 can you verify if this PR helps with your use case , thanks! |
spec/api-net-spec.js
Outdated
it('should throw if given an invalid redirect mode', function (done) { | ||
const requestUrl = '/requestUrl' | ||
try { | ||
const urlRequest = net.request({ |
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.
Would using assert.throws
make sense here?
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 was reusing the existing spec. Have changed it, Thanks!
@deepak1556 Looks good to me! Would be even better if it were possible to know whether or not a redirect happened in follow mode :) But hey, it's possible to do it manually. |
b551f51
to
b14c4dc
Compare
Looks good to me 👍 Thanks @deepak1556 🎆 |
Introduces redirect mode option on
net.request
that takes one offollow, error, manual
and defaults tofollow
. Inmanual
mode aredirect
event is emitted on the request object withstatusCode, method, newURL, responseHeaders
. Callingrequest.followRedirect
will continue with the redirection in manual mode andrequest.abort
to cancel the request.Fixes #8868