follow-redirects 1.15.2 → 1.15.3

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 (2) hide show
  1. package/index.js +16 -4
  2. package/package.json +2 -3
package/index.js CHANGED
@@ -38,6 +38,9 @@ var WriteAfterEndError = createErrorType(
38
38
  "write after end"
39
39
  );
40
40
 
41
+ // istanbul ignore next
42
+ var destroy = Writable.prototype.destroy || noop;
43
+
41
44
  // An HTTP(S) request that can be redirected
42
45
  function RedirectableRequest(options, responseCallback) {
43
46
  // Initialize the request
@@ -68,10 +71,17 @@ function RedirectableRequest(options, responseCallback) {
68
71
  RedirectableRequest.prototype = Object.create(Writable.prototype);
69
72
 
70
73
  RedirectableRequest.prototype.abort = function () {
71
- abortRequest(this._currentRequest);
74
+ destroyRequest(this._currentRequest);
75
+ this._currentRequest.abort();
72
76
  this.emit("abort");
73
77
  };
74
78
 
79
+ RedirectableRequest.prototype.destroy = function (error) {
80
+ destroyRequest(this._currentRequest, error);
81
+ destroy.call(this, error);
82
+ return this;
83
+ };
84
+
75
85
  // Writes buffered data to the current native request
76
86
  RedirectableRequest.prototype.write = function (data, encoding, callback) {
77
87
  // Writing is not allowed if end has been called
@@ -184,6 +194,7 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
184
194
  self.removeListener("abort", clearTimer);
185
195
  self.removeListener("error", clearTimer);
186
196
  self.removeListener("response", clearTimer);
197
+ self.removeListener("close", clearTimer);
187
198
  if (callback) {
188
199
  self.removeListener("timeout", callback);
189
200
  }
@@ -210,6 +221,7 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
210
221
  this.on("abort", clearTimer);
211
222
  this.on("error", clearTimer);
212
223
  this.on("response", clearTimer);
224
+ this.on("close", clearTimer);
213
225
 
214
226
  return this;
215
227
  };
@@ -361,7 +373,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
361
373
  }
362
374
 
363
375
  // The response is a redirect, so abort the current request
364
- abortRequest(this._currentRequest);
376
+ destroyRequest(this._currentRequest);
365
377
  // Discard the remainder of the response to avoid waiting for data
366
378
  response.destroy();
367
379
 
@@ -590,12 +602,12 @@ function createErrorType(code, message, baseClass) {
590
602
  return CustomError;
591
603
  }
592
604
 
593
- function abortRequest(request) {
605
+ function destroyRequest(request, error) {
594
606
  for (var event of events) {
595
607
  request.removeListener(event, eventHandlers[event]);
596
608
  }
597
609
  request.on("error", noop);
598
- request.abort();
610
+ request.destroy(error);
599
611
  }
600
612
 
601
613
  function isSubdomain(subdomain, domain) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "follow-redirects",
3
- "version": "1.15.2",
3
+ "version": "1.15.3",
4
4
  "description": "HTTP and HTTPS modules that follow redirects.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -11,9 +11,8 @@
11
11
  "node": ">=4.0"
12
12
  },
13
13
  "scripts": {
14
- "test": "npm run lint && npm run mocha",
15
14
  "lint": "eslint *.js test",
16
- "mocha": "nyc mocha"
15
+ "test": "nyc mocha"
17
16
  },
18
17
  "repository": {
19
18
  "type": "git",