mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] Add x-forward-* headers for WebSocket requests. Closes #74
This commit is contained in:
parent
d6c543691b
commit
0eb4917ded
@ -351,6 +351,20 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
|
||||
//
|
||||
return socket.destroy();
|
||||
}
|
||||
|
||||
//
|
||||
// Add common proxy headers to the request so that they can
|
||||
// be availible to the proxy target server:
|
||||
//
|
||||
// * `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.connection.socket) {
|
||||
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
|
||||
req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
|
||||
req.headers['x-forwarded-proto'] = req.connection.pair ? 'https' : 'http';
|
||||
}
|
||||
|
||||
//
|
||||
// Helper function for setting appropriate socket values:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user