follow-redirects 1.5.5 → 1.5.9
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 +23 -7
- package/package.json +2 -3
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
|
-
|
88
|
-
if (
|
89
|
-
|
93
|
+
// Shift parameters if necessary
|
94
|
+
if (typeof data === "function") {
|
95
|
+
callback = data;
|
96
|
+
data = encoding = null;
|
90
97
|
}
|
91
|
-
else {
|
92
|
-
|
93
|
-
|
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
|
@@ -129,6 +141,10 @@ RedirectableRequest.prototype._performRequest = function () {
|
|
129
141
|
// Load the native protocol
|
130
142
|
var protocol = this._options.protocol;
|
131
143
|
var nativeProtocol = this._options.nativeProtocols[protocol];
|
144
|
+
if (!nativeProtocol) {
|
145
|
+
this.emit("error", new Error("Unsupported protocol " + protocol));
|
146
|
+
return;
|
147
|
+
}
|
132
148
|
|
133
149
|
// If specified, use the agent corresponding to the protocol
|
134
150
|
// (HTTP and HTTPS use different types of agents)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "follow-redirects",
|
3
|
-
"version": "1.5.
|
3
|
+
"version": "1.5.9",
|
4
4
|
"description": "HTTP and HTTPS modules that follow redirects.",
|
5
5
|
"main": "index.js",
|
6
6
|
"engines": {
|
@@ -44,10 +44,9 @@
|
|
44
44
|
"https.js"
|
45
45
|
],
|
46
46
|
"dependencies": {
|
47
|
-
"debug": "
|
47
|
+
"debug": "=3.1.0"
|
48
48
|
},
|
49
49
|
"devDependencies": {
|
50
|
-
"bluebird": "^3.5.1",
|
51
50
|
"concat-stream": "^1.6.0",
|
52
51
|
"coveralls": "^3.0.0",
|
53
52
|
"eslint": "^4.19.1",
|