follow-redirects 1.2.1 → 1.2.5
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/LICENSE +19 -0
- package/index.js +28 -6
- package/package.json +6 -3
package/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright 2017 Olivier Lalonde <olalonde@gmail.com>, James Talmage <james@talmage.io>, Ruben Verborgh
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
package/index.js
CHANGED
@@ -42,6 +42,17 @@ function RedirectableRequest(options, responseCallback) {
|
|
42
42
|
self._processResponse(response);
|
43
43
|
};
|
44
44
|
|
45
|
+
// Complete the URL object when necessary
|
46
|
+
if (!options.pathname && options.path) {
|
47
|
+
var searchPos = options.path.indexOf('?');
|
48
|
+
if (searchPos < 0) {
|
49
|
+
options.pathname = options.path;
|
50
|
+
} else {
|
51
|
+
options.pathname = options.path.substring(0, searchPos);
|
52
|
+
options.search = options.path.substring(searchPos);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
45
56
|
// Perform the first request
|
46
57
|
this._performRequest();
|
47
58
|
}
|
@@ -57,7 +68,7 @@ RedirectableRequest.prototype._performRequest = function () {
|
|
57
68
|
}
|
58
69
|
|
59
70
|
// Create the native request
|
60
|
-
var nativeProtocol = nativeProtocols[
|
71
|
+
var nativeProtocol = nativeProtocols[protocol];
|
61
72
|
var request = this._currentRequest =
|
62
73
|
nativeProtocol.request(this._options, this._onNativeResponse);
|
63
74
|
this._currentUrl = url.format(this._options);
|
@@ -73,7 +84,7 @@ RedirectableRequest.prototype._performRequest = function () {
|
|
73
84
|
|
74
85
|
// End a redirected request
|
75
86
|
// (The first request must be ended explicitly with RedirectableRequest#end)
|
76
|
-
if (this.
|
87
|
+
if (this._isRedirect) {
|
77
88
|
// If the request doesn't have en entity, end directly.
|
78
89
|
var bufferedWrites = this._bufferedWrites;
|
79
90
|
if (bufferedWrites.length === 0) {
|
@@ -117,13 +128,24 @@ RedirectableRequest.prototype._processResponse = function (response) {
|
|
117
128
|
// that the target resource resides temporarily under a different URI
|
118
129
|
// and the user agent MUST NOT change the request method
|
119
130
|
// if it performs an automatic redirection to that URI.
|
131
|
+
var header;
|
132
|
+
var headers = this._options.headers;
|
120
133
|
if (response.statusCode !== 307 && !(this._options.method in safeMethods)) {
|
121
134
|
this._options.method = 'GET';
|
122
135
|
// Drop a possible entity and headers related to it
|
123
136
|
this._bufferedWrites = [];
|
124
|
-
for (
|
137
|
+
for (header in headers) {
|
125
138
|
if (/^content-/i.test(header)) {
|
126
|
-
delete
|
139
|
+
delete headers[header];
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
// Drop the Host header, as the redirect might lead to a different host
|
145
|
+
if (!this._isRedirect) {
|
146
|
+
for (header in headers) {
|
147
|
+
if (/^host$/i.test(header)) {
|
148
|
+
delete headers[header];
|
127
149
|
}
|
128
150
|
}
|
129
151
|
}
|
@@ -132,7 +154,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
|
|
132
154
|
var redirectUrl = url.resolve(this._currentUrl, location);
|
133
155
|
debug('redirecting to', redirectUrl);
|
134
156
|
Object.assign(this._options, url.parse(redirectUrl));
|
135
|
-
this.
|
157
|
+
this._isRedirect = true;
|
136
158
|
this._performRequest();
|
137
159
|
} else {
|
138
160
|
// The response is not a redirect; return it as-is
|
@@ -171,7 +193,7 @@ RedirectableRequest.prototype.setTimeout = function (timeout, callback) {
|
|
171
193
|
};
|
172
194
|
|
173
195
|
// Writes buffered data to the current native request
|
174
|
-
RedirectableRequest.prototype.
|
196
|
+
RedirectableRequest.prototype.write = function (data, encoding, callback) {
|
175
197
|
this._currentRequest.write(data, encoding, callback);
|
176
198
|
this._bufferedWrites.push({data: data, encoding: encoding});
|
177
199
|
};
|
package/package.json
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "follow-redirects",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.5",
|
4
4
|
"description": "HTTP and HTTPS modules that follow redirects.",
|
5
5
|
"main": "index.js",
|
6
|
+
"engines": {
|
7
|
+
"node": ">=4.0"
|
8
|
+
},
|
6
9
|
"scripts": {
|
7
10
|
"test": "xo && BLUEBIRD_DEBUG=1 nyc mocha"
|
8
11
|
},
|
@@ -39,11 +42,11 @@
|
|
39
42
|
"https.js"
|
40
43
|
],
|
41
44
|
"dependencies": {
|
42
|
-
"debug": "^2.
|
45
|
+
"debug": "^2.6.9"
|
43
46
|
},
|
44
47
|
"devDependencies": {
|
45
48
|
"bluebird": "^3.4.0",
|
46
|
-
"concat-stream": "^1.5.
|
49
|
+
"concat-stream": "^1.5.2",
|
47
50
|
"coveralls": "^2.11.15",
|
48
51
|
"express": "^4.13.0",
|
49
52
|
"mocha": "^3.2.0",
|