simple-http-proxy
Advanced tools
Comparing version
19
index.js
@@ -34,2 +34,11 @@ | ||
var xforward; | ||
// x-forward headers | ||
if (opts.xforward) { | ||
xforward = {}; | ||
['proto', 'host', 'path', 'port'].forEach(function(header) { | ||
xforward[header] = opts.xforward[header] || 'x-forwarded-' + header; | ||
}); | ||
} | ||
return function simpleHttpProxy(req, res, next) { | ||
@@ -58,3 +67,3 @@ // Get our forwarding info | ||
// Enable forwarding headers | ||
if(opts.xforward) { | ||
if(xforward) { | ||
// Get the path at which the middleware is mounted | ||
@@ -67,7 +76,7 @@ var resPath = req.originalUrl.replace(req.url, ''); | ||
// Pass along our headers | ||
options.headers[opts.xforward.proto || 'x-forwarded-proto'] = req.connection.encrypted ? 'https' : 'http'; | ||
options.headers[opts.xforward.host || 'x-forwarded-host'] = hostInfo[0]; | ||
options.headers[opts.xforward.path || 'x-forwarded-path'] = resPath; | ||
options.headers[xforward.proto] = req.headers[xforward.proto] || req.connection.encrypted ? 'https' : 'http'; | ||
options.headers[xforward.host] = req.headers[xforward.host] || hostInfo[0]; | ||
options.headers[xforward.path] = req.headers[xforward.path] || resPath; | ||
if (hostInfo[1]) options.headers[opts.xforward.port || 'x-forwarded-port'] = hostInfo[1]; | ||
if (hostInfo[1]) options.headers[xforward.port] = req.headers[xforward.port] || hostInfo[1]; | ||
} | ||
@@ -74,0 +83,0 @@ |
{ | ||
"name": "simple-http-proxy", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"description": "Simple proxy middleware", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
8351
2.97%198
4.21%