Socket
Socket
Sign inDemoInstall

follow-redirects

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

follow-redirects - npm Package Compare versions

Comparing version 1.9.0 to 1.9.1

59

index.js

@@ -9,6 +9,2 @@ var url = require("url");

// RFC7231§4.2.1: Of the request methods defined by this specification,
// the GET, HEAD, OPTIONS, and TRACE methods are defined to be safe.
var SAFE_METHODS = { GET: true, HEAD: true, OPTIONS: true, TRACE: true };
// Create handlers that pass events from native requests

@@ -309,19 +305,15 @@ var eventHandlers = Object.create(null);

// RFC7231§6.4: Automatic redirection needs to done with
// care for methods not known to be safe […],
// since the user might not wish to redirect an unsafe request.
// RFC7231§6.4.7: The 307 (Temporary Redirect) status code indicates
// that the target resource resides temporarily under a different URI
// and the user agent MUST NOT change the request method
// if it performs an automatic redirection to that URI.
var header;
var headers = this._options.headers;
if (statusCode !== 307 && !(this._options.method in SAFE_METHODS)) {
// care for methods not known to be safe, […]
// RFC7231§6.4.2–3: For historical reasons, a user agent MAY change
// the request method from POST to GET for the subsequent request.
if ((statusCode === 301 || statusCode === 302) && this._options.method === "POST" ||
// RFC7231§6.4.4: The 303 (See Other) status code indicates that
// the server is redirecting the user agent to a different resource […]
// A user agent can perform a retrieval request targeting that URI
// (a GET or HEAD request if using HTTP) […]
(statusCode === 303) && !/^(?:GET|HEAD)$/.test(this._options.method)) {
this._options.method = "GET";
// Drop a possible entity and headers related to it
this._requestBodyBuffers = [];
for (header in headers) {
if (/^content-/i.test(header)) {
delete headers[header];
}
}
removeMatchingHeaders(/^content-/i, this._options.headers);
}

@@ -331,13 +323,12 @@

if (!this._isRedirect) {
for (header in headers) {
if (/^host$/i.test(header)) {
delete headers[header];
}
}
removeMatchingHeaders(/^host$/i, this._options.headers);
}
// Perform the redirected request
// Create the redirected request
var redirectUrl = url.resolve(this._currentUrl, location);
debug("redirecting to", redirectUrl);
this._isRedirect = true;
Object.assign(this._options, url.parse(redirectUrl));
// Evaluate the beforeRedirect callback
if (typeof this._options.beforeRedirect === "function") {

@@ -353,4 +344,12 @@ try {

}
this._isRedirect = true;
this._performRequest();
// Perform the redirected request
try {
this._performRequest();
}
catch (cause) {
var error = new Error("Cannot redirect: " + cause.message);
error.cause = cause;
this.emit("error", error);
}
}

@@ -454,4 +453,12 @@ else {

function removeMatchingHeaders(regex, headers) {
for (var header in headers) {
if (regex.test(header)) {
delete headers[header];
}
}
}
// Exports
module.exports = wrap({ http: http, https: https });
module.exports.wrap = wrap;
{
"name": "follow-redirects",
"version": "1.9.0",
"version": "1.9.1",
"description": "HTTP and HTTPS modules that follow redirects.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -140,4 +140,4 @@ ## Follow Redirects

- [Ruben Verborgh](https://ruben.verborgh.org/)
- Olivier Lalonde (olalonde@gmail.com)
- James Talmage (james@talmage.io)
- [Olivier Lalonde](mailto:olalonde@gmail.com)
- [James Talmage](mailto:james@talmage.io)

@@ -144,0 +144,0 @@ ## License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc