mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
working on x-forwarded-for
This commit is contained in:
parent
916d44e3d2
commit
133240937d
@ -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.
|
||||
@ -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']){
|
||||
|
||||
@ -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;
|
||||
|
||||
//
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user