Comparing version 0.1.4 to 0.1.5
@@ -12,3 +12,5 @@ /* | ||
var debug = false; | ||
var debug = false, | ||
retry_failed = false; | ||
var defaults = {}; | ||
@@ -110,6 +112,9 @@ | ||
if (opts.retry_failed) | ||
retry_failed = opts.retry_failed; | ||
return exports.send; | ||
} | ||
exports.send = function(req, res){ | ||
exports.send = function(req, res) { | ||
@@ -130,3 +135,3 @@ log('Proxying request to ' + req.url); | ||
var header_func = opts.lowercase ? function(h){ return h } : upperize; | ||
var header_func = opts.lowercase ? function(h) { return h } : upperize; | ||
// req.connection.setTimeout(timeout); // we'll set or own timer | ||
@@ -157,3 +162,3 @@ | ||
var done = function(err){ | ||
var done = function(err) { | ||
if (returned) return; | ||
@@ -164,3 +169,3 @@ cb && cb(err, res); | ||
var proxyError = function(err){ | ||
var proxyError = function(err) { | ||
error = true; | ||
@@ -171,4 +176,12 @@ if (timer) clearTimeout(timer); | ||
if (!res.headersSent) { | ||
var code = req.aborted ? 499 : (errors[err.code] || 500); | ||
res.writeHead(code, {'Content-Type': 'text/plain', 'Connection': 'close'}); | ||
if (retry_failed === true && !opts.retried) { | ||
// retry is enabled, so wait one second and resend the request | ||
return setTimeout(function() { | ||
opts.retried = true; | ||
exports.send(req, res, opts, cb); | ||
}, 1000); | ||
} else { | ||
var code = req.aborted ? 499 : (errors[err.code] || 500); | ||
res.writeHead(code, {'Content-Type': 'text/plain', 'Connection': 'close'}); | ||
} | ||
} | ||
@@ -189,3 +202,3 @@ | ||
var proxyRequest = http.request(request_opts, function(response){ | ||
var proxyRequest = http.request(request_opts, function(response) { | ||
@@ -230,3 +243,3 @@ if (timer) clearTimeout(timer); | ||
response.once('end', function(){ | ||
response.once('end', function() { | ||
// log('Proxy response ended.') | ||
@@ -252,3 +265,3 @@ if (error) return; | ||
req.once('close', function() { | ||
// log('Request closed.') | ||
log('Request closed.') | ||
if (!error) proxyRequest.abort(); | ||
@@ -278,4 +291,8 @@ }); | ||
// if we proxied a HEAD request and we received a body, we would get this error | ||
if (req.method == 'HEAD' && err.code == 'HPE_INVALID_CONSTANT') { | ||
log('HEAD response contained a body!') | ||
if (err.code == 'HPE_INVALID_CONSTANT') { | ||
if (req.method == 'HEAD') { | ||
log('HEAD response contained a body!') | ||
} else { | ||
log('Invalid Content-Length!'); | ||
} | ||
return res.end(); | ||
@@ -290,3 +307,3 @@ } | ||
} else { | ||
req.once('end', function(){ | ||
req.once('end', function() { | ||
if (!error) proxyRequest.end(); | ||
@@ -293,0 +310,0 @@ }); |
{ | ||
"name": "under", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Fast reverse HTTP proxy with load balancing and queue support.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha test" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": "", |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
21403
14
685
2
10