follow-redirects
Advanced tools
Comparing version 1.13.2 to 1.13.3
57
index.js
@@ -64,2 +64,13 @@ var url = require("url"); | ||
RedirectableRequest.prototype.abort = function () { | ||
// Abort the internal request | ||
this._currentRequest.removeAllListeners(); | ||
this._currentRequest.on("error", noop); | ||
this._currentRequest.abort(); | ||
// Abort this request | ||
this.emit("abort"); | ||
this.removeAllListeners(); | ||
}; | ||
// Writes buffered data to the current native request | ||
@@ -144,14 +155,35 @@ RedirectableRequest.prototype.write = function (data, encoding, callback) { | ||
RedirectableRequest.prototype.setTimeout = function (msecs, callback) { | ||
var self = this; | ||
if (callback) { | ||
this.once("timeout", callback); | ||
this.on("timeout", callback); | ||
} | ||
// Sets up a timer to trigger a timeout event | ||
function startTimer() { | ||
if (self._timeout) { | ||
clearTimeout(self._timeout); | ||
} | ||
self._timeout = setTimeout(function () { | ||
self.emit("timeout"); | ||
clearTimer(); | ||
}, msecs); | ||
} | ||
// Prevent a timeout from triggering | ||
function clearTimer() { | ||
clearTimeout(this._timeout); | ||
if (callback) { | ||
self.removeListener("timeout", callback); | ||
} | ||
if (!this.socket) { | ||
self._currentRequest.removeListener("socket", startTimer); | ||
} | ||
} | ||
// Start the timer when the socket is opened | ||
if (this.socket) { | ||
startTimer(this, msecs); | ||
startTimer(); | ||
} | ||
else { | ||
var self = this; | ||
this._currentRequest.once("socket", function () { | ||
startTimer(self, msecs); | ||
}); | ||
this._currentRequest.once("socket", startTimer); | ||
} | ||
@@ -165,16 +197,5 @@ | ||
function startTimer(request, msecs) { | ||
clearTimeout(request._timeout); | ||
request._timeout = setTimeout(function () { | ||
request.emit("timeout"); | ||
}, msecs); | ||
} | ||
function clearTimer() { | ||
clearTimeout(this._timeout); | ||
} | ||
// Proxy all other public ClientRequest methods | ||
[ | ||
"abort", "flushHeaders", "getHeader", | ||
"flushHeaders", "getHeader", | ||
"setNoDelay", "setSocketKeepAlive", | ||
@@ -181,0 +202,0 @@ ].forEach(function (method) { |
{ | ||
"name": "follow-redirects", | ||
"version": "1.13.2", | ||
"version": "1.13.3", | ||
"description": "HTTP and HTTPS modules that follow redirects.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
25071
486