follow-redirects
Advanced tools
Comparing version 1.0.0 to 1.1.0
46
index.js
@@ -32,2 +32,3 @@ 'use strict'; | ||
this._redirectCount = 0; | ||
this._bufferedWrites = []; | ||
@@ -73,5 +74,22 @@ // Attach a callback if passed | ||
// The first request is explicitly ended in RedirectableRequest#end | ||
// End a redirected request | ||
// (The first request must be ended explicitly with RedirectableRequest#end) | ||
if (this._currentResponse) { | ||
request.end(); | ||
// If no body was written to the original request, or the method was changed to GET, | ||
// end the redirected request (without writing a body). | ||
var bufferedWrites = this._bufferedWrites; | ||
if (bufferedWrites.length === 0 || this._options.method === 'GET') { | ||
request.end(); | ||
// The body of the original request must be added to the redirected request. | ||
} else { | ||
var i = 0; | ||
(function writeNext() { | ||
if (i < bufferedWrites.length) { | ||
var bufferedWrite = bufferedWrites[i++]; | ||
request.write(bufferedWrite.data, bufferedWrite.encoding, writeNext); | ||
} else { | ||
request.end(); | ||
} | ||
})(); | ||
} | ||
} | ||
@@ -119,3 +137,7 @@ }; | ||
response.responseUrl = this._currentUrl; | ||
return this.emit('response', response); | ||
this.emit('response', response); | ||
// Clean up | ||
delete this._options; | ||
delete this._bufferedWrites; | ||
} | ||
@@ -129,7 +151,2 @@ }; | ||
// Ends the current native request | ||
RedirectableRequest.prototype.end = function (data, encoding, callback) { | ||
this._currentRequest.end(data, encoding, callback); | ||
}; | ||
// Flushes the headers of the current native request | ||
@@ -156,6 +173,15 @@ RedirectableRequest.prototype.flushHeaders = function () { | ||
// Writes buffered data to the current native request | ||
RedirectableRequest.prototype._write = function (chunk, encoding, callback) { | ||
this._currentRequest.write(chunk, encoding, callback); | ||
RedirectableRequest.prototype._write = function (data, encoding, callback) { | ||
this._currentRequest.write(data, encoding, callback); | ||
this._bufferedWrites.push({data: data, encoding: encoding}); | ||
}; | ||
// Ends the current native request | ||
RedirectableRequest.prototype.end = function (data, encoding, callback) { | ||
this._currentRequest.end(data, encoding, callback); | ||
if (data) { | ||
this._bufferedWrites.push({data: data, encoding: encoding}); | ||
} | ||
}; | ||
// Export a redirecting wrapper for each native protocol | ||
@@ -162,0 +188,0 @@ Object.keys(nativeProtocols).forEach(function (protocol) { |
{ | ||
"name": "follow-redirects", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "HTTP and HTTPS modules that follow redirects.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14584
188
2