follow-redirects
Advanced tools
Comparing version 0.0.4 to 0.0.5
20
index.js
var nativeHttps = require('https'), | ||
nativeHttp = require('http'), | ||
url = require('url'), | ||
_ = require('underscore'); | ||
_ = require('underscore'), | ||
debug = require('debug')('follow-redirects'); | ||
@@ -50,3 +51,3 @@ var maxRedirects = module.exports.maxRedirects = 5; | ||
*/ | ||
var reqUrl; | ||
var reqUrl, method; | ||
if (typeof options === 'string') { | ||
@@ -62,2 +63,3 @@ reqUrl = options; | ||
*/ | ||
debug(options); | ||
var clientRequest = h.__proto__.request(options, redirectCallback(reqUrl, redirect)); | ||
@@ -72,3 +74,6 @@ | ||
function redirectCallback (reqUrl, redirect) { | ||
debug('redirectCallback'); | ||
return function (res) { | ||
debug('headers:'); | ||
debug(res.headers); | ||
// status must be 300-399 for redirects | ||
@@ -92,2 +97,3 @@ if (res.statusCode < 300 || res.statusCode > 399) { | ||
var redirectUrl = url.resolve(reqUrl, res.headers['location']); | ||
debug('redirectUrl', redirectUrl); | ||
// we need to call the right api (http vs https) depending on protocol | ||
@@ -99,7 +105,8 @@ var proto = url.parse(redirectUrl).protocol; | ||
// Break url in parts | ||
var searchname = url.parse(redirectUrl).search; | ||
var hostname = url.parse(redirectUrl).hostname; | ||
var pathname = url.parse(redirectUrl).pathname; | ||
var parsedUrl = url.parse(redirectUrl); | ||
var searchname = parsedUrl.search || ''; | ||
var hostname = parsedUrl.hostname; | ||
var pathname = parsedUrl.pathname; | ||
var redirectOptions = options; | ||
var redirectOptions = typeof options === 'string' ? {} : options; | ||
redirectOptions.reqUrl = redirectUrl; | ||
@@ -109,2 +116,3 @@ redirectOptions.hostname = hostname; | ||
debug('redirectOptions', redirectOptions); | ||
var out = module.exports[proto].get(redirectOptions, redirectCallback(reqUrl, redirect), redirect); | ||
@@ -111,0 +119,0 @@ |
{ | ||
"name": "follow-redirects", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "HTTP and HTTPS modules that follow redirects.", | ||
@@ -24,7 +24,8 @@ "main": "index.js", | ||
"author": { | ||
"name": "Olivier Lalonde" | ||
, "email": "olalonde@gmail.com" | ||
, "url": "http://www.syskall.com" | ||
"name": "Olivier Lalonde", | ||
"email": "olalonde@gmail.com", | ||
"url": "http://www.syskall.com" | ||
}, | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"underscore": "" | ||
@@ -31,0 +32,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8506
6
193
2
+ Addeddebug@^2.2.0
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)