follow-redirects 1.10.0 → 1.11.0
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 +12 -4
- package/package.json +1 -1
package/index.js
CHANGED
@@ -335,15 +335,20 @@ RedirectableRequest.prototype._processResponse = function (response) {
|
|
335
335
|
}
|
336
336
|
|
337
337
|
// Drop the Host header, as the redirect might lead to a different host
|
338
|
-
|
339
|
-
|
340
|
-
}
|
338
|
+
var previousHostName = removeMatchingHeaders(/^host$/i, this._options.headers) ||
|
339
|
+
url.parse(this._currentUrl).hostname;
|
341
340
|
|
342
341
|
// Create the redirected request
|
343
342
|
var redirectUrl = url.resolve(this._currentUrl, location);
|
344
343
|
debug("redirecting to", redirectUrl);
|
345
344
|
this._isRedirect = true;
|
346
|
-
|
345
|
+
var redirectUrlParts = url.parse(redirectUrl);
|
346
|
+
Object.assign(this._options, redirectUrlParts);
|
347
|
+
|
348
|
+
// Drop the Authorization header if redirecting to another host
|
349
|
+
if (redirectUrlParts.hostname !== previousHostName) {
|
350
|
+
removeMatchingHeaders(/^authorization$/i, this._options.headers);
|
351
|
+
}
|
347
352
|
|
348
353
|
// Evaluate the beforeRedirect callback
|
349
354
|
if (typeof this._options.beforeRedirect === "function") {
|
@@ -465,11 +470,14 @@ function urlToOptions(urlObject) {
|
|
465
470
|
}
|
466
471
|
|
467
472
|
function removeMatchingHeaders(regex, headers) {
|
473
|
+
var lastValue;
|
468
474
|
for (var header in headers) {
|
469
475
|
if (regex.test(header)) {
|
476
|
+
lastValue = headers[header];
|
470
477
|
delete headers[header];
|
471
478
|
}
|
472
479
|
}
|
480
|
+
return lastValue;
|
473
481
|
}
|
474
482
|
|
475
483
|
function createErrorType(code, defaultMessage) {
|