mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Routing Proxy was not sending x-forward-*. Fixing It...
This commit is contained in:
parent
025adc2912
commit
916d44e3d2
@ -163,6 +163,10 @@ RoutingProxy.prototype.close = function () {
|
||||
});
|
||||
};
|
||||
|
||||
function getProto(req) {
|
||||
return req.isSpdy ? 'https' : (req.connection.pair ? 'https' : 'http');
|
||||
}
|
||||
|
||||
//
|
||||
// ### function proxyRequest (req, res, [port, host, paused])
|
||||
// #### @req {ServerRequest} Incoming HTTP Request to proxy.
|
||||
@ -176,7 +180,41 @@ RoutingProxy.prototype.close = function () {
|
||||
//
|
||||
RoutingProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
options = options || {};
|
||||
|
||||
|
||||
//
|
||||
// Add common proxy headers to the request so that they can
|
||||
// be availible to the proxy target server. If the proxy is
|
||||
// part of proxy chain it will append the address:
|
||||
//
|
||||
// * `x-forwarded-for`: IP Address of the original request
|
||||
// * `x-forwarded-proto`: Protocol of the original request
|
||||
// * `x-forwarded-port`: Port of the original request.
|
||||
//
|
||||
if (this.enable.xforward && req.connection && req.socket) {
|
||||
if (req.headers['x-forwarded-for']){
|
||||
var addressToAppend = "," + req.connection.remoteAddress || req.socket.remoteAddress;
|
||||
req.headers['x-forwarded-for'] += addressToAppend;
|
||||
}
|
||||
else {
|
||||
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.socket.remoteAddress;
|
||||
}
|
||||
|
||||
if (req.headers['x-forwarded-port']){
|
||||
var portToAppend = "," + req.connection.remotePort || req.socket.remotePort;
|
||||
req.headers['x-forwarded-port'] += portToAppend;
|
||||
}
|
||||
else {
|
||||
req.headers['x-forwarded-port'] = req.connection.remotePort || req.socket.remotePort;
|
||||
}
|
||||
|
||||
if (req.headers['x-forwarded-proto']){
|
||||
var protoToAppend = "," + getProto(req);
|
||||
req.headers['x-forwarded-proto'] += protoToAppend;
|
||||
}
|
||||
else {
|
||||
req.headers['x-forwarded-proto'] = getProto(req);
|
||||
}
|
||||
}
|
||||
var location;
|
||||
|
||||
//
|
||||
@ -248,6 +286,40 @@ RoutingProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
RoutingProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options) {
|
||||
options = options || {};
|
||||
|
||||
//
|
||||
// Add common proxy headers to the request so that they can
|
||||
// be availible to the proxy target server. If the proxy is
|
||||
// part of proxy chain it will append the address:
|
||||
//
|
||||
// * `x-forwarded-for`: IP Address of the original request
|
||||
// * `x-forwarded-proto`: Protocol of the original request
|
||||
// * `x-forwarded-port`: Port of the original request.
|
||||
//
|
||||
if (this.enable.xforward && req.connection && req.socket) {
|
||||
if (req.headers['x-forwarded-for']){
|
||||
var addressToAppend = "," + req.connection.remoteAddress || req.socket.remoteAddress;
|
||||
req.headers['x-forwarded-for'] += addressToAppend;
|
||||
}
|
||||
else {
|
||||
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.socket.remoteAddress;
|
||||
}
|
||||
|
||||
if (req.headers['x-forwarded-port']){
|
||||
var portToAppend = "," + req.connection.remotePort || req.socket.remotePort;
|
||||
req.headers['x-forwarded-port'] += portToAppend;
|
||||
}
|
||||
else {
|
||||
req.headers['x-forwarded-port'] = req.connection.remotePort || req.socket.remotePort;
|
||||
}
|
||||
|
||||
if (req.headers['x-forwarded-proto']){
|
||||
var protoToAppend = "," + getProto(req);
|
||||
req.headers['x-forwarded-proto'] += protoToAppend;
|
||||
}
|
||||
else {
|
||||
req.headers['x-forwarded-proto'] = getProto(req);
|
||||
}
|
||||
}
|
||||
var location,
|
||||
proxy,
|
||||
key;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user