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.

Files changed (2) hide show
  1. package/index.js +12 -4
  2. 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
- if (!this._isRedirect) {
339
- removeMatchingHeaders(/^host$/i, this._options.headers);
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
- Object.assign(this._options, url.parse(redirectUrl));
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "follow-redirects",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "HTTP and HTTPS modules that follow redirects.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",