http-basic
Advanced tools
Comparing version 2.3.1 to 2.3.2
32
index.js
@@ -17,2 +17,3 @@ 'use strict'; | ||
function request(method, url, options, callback) { | ||
var start = Date.now(); | ||
if (typeof method !== 'string') { | ||
@@ -112,10 +113,15 @@ throw new TypeError('The method must be a string.'); | ||
} | ||
var opts = {}; | ||
Object.keys(options).forEach(function (key) { | ||
opts[key] = options[key]; | ||
}); | ||
options = opts; | ||
if (options.maxRedirects && options.maxRedirects !== Infinity) { | ||
var opts = {}; | ||
Object.keys(options).forEach(function (key) { | ||
opts[key] = options[key]; | ||
}); | ||
options = opts; | ||
options.maxRedirects--; | ||
} | ||
// don't maintain headers through redirects | ||
// This fixes a problem where a POST to http://example.com | ||
// might result in a GET to http://example.co.uk that includes "content-length" | ||
// as a header | ||
options.headers = {}; | ||
return request(duplex ? 'GET' : method, resolveUrl(urlString, res.headers.location), options, callback); | ||
@@ -184,7 +190,7 @@ } else { | ||
function attempt(n) { | ||
console.dir('attempt: ' + n); | ||
request(method, urlString, { | ||
headers: headers, | ||
agent: agent, | ||
timeout: options.timeout, | ||
socketTimeout: options.socketTimeout | ||
timeout: options.timeout | ||
}, function (err, res) { | ||
@@ -218,2 +224,11 @@ var retry = err || res.statusCode >= 400; | ||
console.log(method + ' ' + urlString); | ||
console.dir({ | ||
host: url.hostname, | ||
port: url.port, | ||
path: url.path, | ||
method: method, | ||
headers: headers, | ||
agent: agent | ||
}); | ||
var req = protocols[url.protocol.replace(/\:$/, '')].request({ | ||
@@ -227,2 +242,5 @@ host: url.hostname, | ||
}, function (res) { | ||
var end = Date.now(); | ||
console.log(method + ' ' + urlString + ' (' + res.statusCode + ') - ' + (end - start) + 'ms'); | ||
console.dir(res.headers, {colors: true}); | ||
if (responded) return res.resume(); | ||
@@ -229,0 +247,0 @@ responded = true; |
{ | ||
"name": "http-basic", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "Very low level wrapper arround http.request/https.request", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
21628
454