follow-redirects 1.14.0 → 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.

Files changed (3) hide show
  1. package/debug.js +2 -1
  2. package/index.js +14 -11
  3. package/package.json +1 -1
package/debug.js CHANGED
@@ -6,7 +6,8 @@ module.exports = function () {
6
6
  /* eslint global-require: off */
7
7
  debug = require("debug")("follow-redirects");
8
8
  }
9
- catch (error) {
9
+ catch (error) { /* */ }
10
+ if (typeof debug !== "function") {
10
11
  debug = function () { /* */ };
11
12
  }
12
13
  }
package/index.js CHANGED
@@ -63,12 +63,8 @@ function RedirectableRequest(options, responseCallback) {
63
63
  RedirectableRequest.prototype = Object.create(Writable.prototype);
64
64
 
65
65
  RedirectableRequest.prototype.abort = function () {
66
- // Abort the internal request
67
66
  abortRequest(this._currentRequest);
68
-
69
- // Abort this request
70
67
  this.emit("abort");
71
- this.removeAllListeners();
72
68
  };
73
69
 
74
70
  // Writes buffered data to the current native request
@@ -151,10 +147,8 @@ RedirectableRequest.prototype.removeHeader = function (name) {
151
147
  // Global timeout for all underlying requests
152
148
  RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
153
149
  var self = this;
154
- if (callback) {
155
- this.on("timeout", callback);
156
- }
157
150
 
151
+ // Destroys the socket on timeout
158
152
  function destroyOnTimeout(socket) {
159
153
  socket.setTimeout(msecs);
160
154
  socket.removeListener("timeout", socket.destroy);
@@ -173,18 +167,26 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
173
167
  destroyOnTimeout(socket);
174
168
  }
175
169
 
176
- // Prevent a timeout from triggering
170
+ // Stops a timeout from triggering
177
171
  function clearTimer() {
178
- clearTimeout(this._timeout);
172
+ if (self._timeout) {
173
+ clearTimeout(self._timeout);
174
+ self._timeout = null;
175
+ }
179
176
  if (callback) {
180
177
  self.removeListener("timeout", callback);
181
178
  }
182
- if (!this.socket) {
179
+ if (!self.socket) {
183
180
  self._currentRequest.removeListener("socket", startTimer);
184
181
  }
185
182
  }
186
183
 
187
- // Start the timer when the socket is opened
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
188
190
  if (this.socket) {
189
191
  startTimer(this.socket);
190
192
  }
@@ -192,6 +194,7 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
192
194
  this._currentRequest.once("socket", startTimer);
193
195
  }
194
196
 
197
+ // Clean up on events
195
198
  this.on("socket", destroyOnTimeout);
196
199
  this.once("response", clearTimer);
197
200
  this.once("error", clearTimer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "follow-redirects",
3
- "version": "1.14.0",
3
+ "version": "1.14.4",
4
4
  "description": "HTTP and HTTPS modules that follow redirects.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",