Skip to content

Commit

Permalink
working on x-forwarded-for
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojr authored and indexzero committed Mar 9, 2013
1 parent 916d44e commit 1332409
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 74 deletions.
11 changes: 6 additions & 5 deletions lib/node-http-proxy/http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
req.headers['x-forwarded-proto'] = getProto(req);
}
}
console.log(req.headers);

//
// Emit the `start` event indicating that we have begun the proxy operation.
Expand Down Expand Up @@ -414,21 +415,21 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
// * `x-forwarded-proto`: Protocol of the original request
// * `x-forwarded-port`: Port of the original request.
//
if (this.enable.xforward && req.connection && req.connection.socket) {
if (this.enable.xforward && req.connection) {
if (req.headers['x-forwarded-for']){
var addressToAppend = "," + req.connection.remoteAddress || req.connection.socket.remoteAddress;
var addressToAppend = "," + req.connection.remoteAddress || socket.remoteAddress;
req.headers['x-forwarded-for'] += addressToAppend;
}
else {
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
req.headers['x-forwarded-for'] = req.connection.remoteAddress || socket.remoteAddress;
}

if (req.headers['x-forwarded-port']){
var portToAppend = "," + req.connection.remotePort || req.connection.socket.remotePort;
var portToAppend = "," + req.connection.remotePort || socket.remotePort;
req.headers['x-forwarded-port'] += portToAppend;
}
else {
req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
req.headers['x-forwarded-port'] = req.connection.remotePort || socket.remotePort;
}

if (req.headers['x-forwarded-proto']){
Expand Down
69 changes: 0 additions & 69 deletions lib/node-http-proxy/routing-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,41 +180,6 @@ function getProto(req) {
//
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;

//
Expand Down Expand Up @@ -286,40 +251,6 @@ 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;
Expand Down

0 comments on commit 1332409

Please sign in to comment.