follow-redirects 1.14.3 → 1.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of follow-redirects might be problematic. Click here for more details.
- package/index.js +14 -7
- package/package.json +1 -1
package/index.js
CHANGED
@@ -147,10 +147,8 @@ RedirectableRequest.prototype.removeHeader = function (name) {
|
|
147
147
|
// Global timeout for all underlying requests
|
148
148
|
RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
149
149
|
var self = this;
|
150
|
-
if (callback) {
|
151
|
-
this.on("timeout", callback);
|
152
|
-
}
|
153
150
|
|
151
|
+
// Destroys the socket on timeout
|
154
152
|
function destroyOnTimeout(socket) {
|
155
153
|
socket.setTimeout(msecs);
|
156
154
|
socket.removeListener("timeout", socket.destroy);
|
@@ -169,18 +167,26 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
|
169
167
|
destroyOnTimeout(socket);
|
170
168
|
}
|
171
169
|
|
172
|
-
//
|
170
|
+
// Stops a timeout from triggering
|
173
171
|
function clearTimer() {
|
174
|
-
|
172
|
+
if (self._timeout) {
|
173
|
+
clearTimeout(self._timeout);
|
174
|
+
self._timeout = null;
|
175
|
+
}
|
175
176
|
if (callback) {
|
176
177
|
self.removeListener("timeout", callback);
|
177
178
|
}
|
178
|
-
if (!
|
179
|
+
if (!self.socket) {
|
179
180
|
self._currentRequest.removeListener("socket", startTimer);
|
180
181
|
}
|
181
182
|
}
|
182
183
|
|
183
|
-
//
|
184
|
+
// Attach callback if passed
|
185
|
+
if (callback) {
|
186
|
+
this.on("timeout", callback);
|
187
|
+
}
|
188
|
+
|
189
|
+
// Start the timer if or when the socket is opened
|
184
190
|
if (this.socket) {
|
185
191
|
startTimer(this.socket);
|
186
192
|
}
|
@@ -188,6 +194,7 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
|
188
194
|
this._currentRequest.once("socket", startTimer);
|
189
195
|
}
|
190
196
|
|
197
|
+
// Clean up on events
|
191
198
|
this.on("socket", destroyOnTimeout);
|
192
199
|
this.once("response", clearTimer);
|
193
200
|
this.once("error", clearTimer);
|