net: allow controlling redirects
This commit is contained in:
parent
637bdc239b
commit
3ae62615f4
6 changed files with 312 additions and 6 deletions
|
@ -156,9 +156,15 @@ class ClientRequest extends EventEmitter {
|
|||
urlStr = url.format(urlObj)
|
||||
}
|
||||
|
||||
const redirectPolicy = options.redirect || 'follow'
|
||||
if (!['follow', 'error', 'manual'].includes(redirectPolicy)) {
|
||||
throw new Error('redirect mode should be one of follow, error or manual')
|
||||
}
|
||||
|
||||
let urlRequestOptions = {
|
||||
method: method,
|
||||
url: urlStr
|
||||
url: urlStr,
|
||||
redirect: redirectPolicy
|
||||
}
|
||||
if (options.session) {
|
||||
if (options.session instanceof Session) {
|
||||
|
@ -339,6 +345,10 @@ class ClientRequest extends EventEmitter {
|
|||
return this._write(data, encoding, callback, true)
|
||||
}
|
||||
|
||||
followRedirect () {
|
||||
this.urlRequest.followRedirect()
|
||||
}
|
||||
|
||||
abort () {
|
||||
this.urlRequest.cancel()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue