Comparing version 0.1.1 to 0.1.2
@@ -20,2 +20,3 @@ var needle = require('needle'); | ||
console.log('Got response: ' + (code) + ' -- ' + count + ' pending'); | ||
if (code == 'none') console.log(err); | ||
if (!codes[code]) codes[code] = 0; | ||
@@ -22,0 +23,0 @@ codes[code]++; |
@@ -24,8 +24,9 @@ /* | ||
var errors = { | ||
'ECONNRESET': 502, | ||
'ECONNREFUSED': 503, | ||
'ENOTFOUND': 503, | ||
'ENOENT': 503, | ||
'EMFILE': 599, | ||
'EADDRNOTAVAIL': 599 // no available sockets/ports | ||
'ECONNRESET': 502, // when aborted (timeout) | ||
'ECONNREFUSED': 503, | ||
'EAGAIN': 503, // syscall: 'connect' | ||
'ENOTFOUND': 503, | ||
'ENOENT': 503, | ||
'EMFILE': 599, | ||
'EADDRNOTAVAIL': 599 // no available sockets/ports | ||
} | ||
@@ -42,2 +43,10 @@ | ||
var remove_matching = function(arr, obj) { | ||
return arr.filter(function(el) { | ||
return !Object.keys(el).every(function(key) { | ||
return el[key] === obj[key]; | ||
}); | ||
}) | ||
} | ||
//////////////////////////////////////////////////////////// | ||
@@ -67,6 +76,18 @@ // helpers | ||
var get_ip_address = function(conn){ | ||
return conn.remoteAddress | ||
|| conn.socket | ||
&& conn.socket.remoteAddress; | ||
var flag_backend = function(target) { | ||
// no point in flagging backend if empty or just one | ||
if (!defaults.backends || defaults.backends.length <= 1) | ||
return; | ||
var removed = remove_matching(defaults.backends, target); | ||
if (removed.length == defaults.backends.length) | ||
return log('Unable to find matching backend.'); | ||
log('Flagging server in backend list!'); | ||
defaults.backends = removed; | ||
setTimeout(function() { | ||
log('Unflagging server in backend list!'); | ||
defaults.backends.push(target); | ||
}, defaults.flag_timeout || 10 * 1000) // 10 seconds by default | ||
} | ||
@@ -105,3 +126,3 @@ | ||
var target = opts.backend || defaults.backend || get_target(opts.backends), | ||
backend_name = opts.sign === false ? null : get_backend_name(target); | ||
backend_name = opts.sign === true ? get_backend_name(target) : null; | ||
@@ -119,4 +140,20 @@ var should_timeout = !is_socket_request(req), | ||
request_opts.headers = req.headers; | ||
request_opts.headers['X-Forwarded-For'] = get_ip_address(req.connection); | ||
// include X-Forwarded-(For|Port|Proto) headers | ||
if (req.connection && req.socket) { | ||
var connection_data = { | ||
'For' : req.connection.remoteAddress || req.socket.remoteAddress, | ||
'Port' : req.connection.remotePort || req.socket.remotePort, | ||
'Proto' : req.secure ? 'https' : 'http' | ||
} | ||
for (var key in connection_data) { | ||
var name = 'X-Forwarded-' + key; | ||
if (request_opts.headers[name]) | ||
request_opts.headers[name] += ', ' + connection_data[key]; | ||
else | ||
request_opts.headers[name] = connection_data[key]; | ||
} | ||
} | ||
var done = function(err){ | ||
@@ -144,2 +181,6 @@ if (returned) return; | ||
// if error code is known (502, 503, etc), mark backend as unavailable | ||
if (errors[err.code]) | ||
flag_backend(target); | ||
done(err); | ||
@@ -261,2 +302,2 @@ }; | ||
} | ||
} |
@@ -40,3 +40,3 @@ var proxy = require('./proxy'); | ||
requests.active++; | ||
var req_res = requests.queued.shift(); | ||
var req_res = requests.queued.shift(); // returns first element | ||
proxy_request(req_res[0], req_res[1]); | ||
@@ -43,0 +43,0 @@ } else { |
{ | ||
"name": "under", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Fast reverse HTTP proxy with load balancing and queue support.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
16975
15
552
2
8