follow-redirects 1.5.6 → 1.5.7

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 +19 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -58,9 +58,15 @@ RedirectableRequest.prototype = Object.create(Writable.prototype);
58
58
 
59
59
  // Writes buffered data to the current native request
60
60
  RedirectableRequest.prototype.write = function (data, encoding, callback) {
61
+ // Validate input and shift parameters if necessary
61
62
  if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) {
62
63
  throw new Error("data should be a string, Buffer or Uint8Array");
63
64
  }
65
+ if (typeof encoding === "function") {
66
+ callback = encoding;
67
+ encoding = null;
68
+ }
69
+
64
70
  // Ignore empty buffers, since writing them doesn't invoke the callback
65
71
  // https://github.com/nodejs/node/issues/22066
66
72
  if (data.length === 0) {
@@ -84,15 +90,21 @@ RedirectableRequest.prototype.write = function (data, encoding, callback) {
84
90
 
85
91
  // Ends the current native request
86
92
  RedirectableRequest.prototype.end = function (data, encoding, callback) {
87
- var currentRequest = this._currentRequest;
88
- if (!data) {
89
- currentRequest.end(null, null, callback);
93
+ // Shift parameters if necessary
94
+ if (typeof data === "function") {
95
+ callback = data;
96
+ data = encoding = null;
90
97
  }
91
- else {
92
- this.write(data, encoding, function () {
93
- currentRequest.end(null, null, callback);
94
- });
98
+ else if (typeof encoding === "function") {
99
+ callback = encoding;
100
+ encoding = null;
95
101
  }
102
+
103
+ // Write data and end
104
+ var currentRequest = this._currentRequest;
105
+ this.write(data || "", encoding, function () {
106
+ currentRequest.end(null, null, callback);
107
+ });
96
108
  };
97
109
 
98
110
  // Sets a header value on the current native request
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "follow-redirects",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
4
4
  "description": "HTTP and HTTPS modules that follow redirects.",
5
5
  "main": "index.js",
6
6
  "engines": {