Fix up remoteAddress for WebSocket connections
This commit is contained in:
parent
87a23bd3c8
commit
438a3161d0
|
@ -38,13 +38,17 @@ class WebSocketClient extends TelnetClient {
|
||||||
this.ws.on('message', data => this._data(data));
|
this.ws.on('message', data => this._data(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
setClient(client) {
|
setClient(client, httpRequest) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
|
// Support X-Forwarded-For and X-Real-IP headers for proxied connections
|
||||||
|
this.resolvedRemoteAddress =
|
||||||
|
(this.client.proxied && (httpRequest.headers['x-forwarded-for'] || httpRequest.headers['x-real-ip'])) ||
|
||||||
|
httpRequest.connection.remoteAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
get remoteAddress() {
|
get remoteAddress() {
|
||||||
// Support X-Forwarded-For and X-Real-IP headers for proxied connections
|
return this.resolvedRemoteAddress;
|
||||||
return (this.client.proxied && (req.headers['x-forwarded-for'] || req.headers['x-real-ip'])) || req.connection.remoteAddress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_write(data, encoding, cb) {
|
_write(data, encoding, cb) {
|
||||||
|
@ -62,7 +66,10 @@ class WebSocketClient extends TelnetClient {
|
||||||
}(ws);
|
}(ws);
|
||||||
|
|
||||||
super(wsDuplex);
|
super(wsDuplex);
|
||||||
wsDuplex.setClient(this);
|
wsDuplex.setClient(this, req);
|
||||||
|
|
||||||
|
// fudge remoteAddress on socket, which is now TelnetSocket
|
||||||
|
this.socket.remoteAddress = wsDuplex.remoteAddress;
|
||||||
|
|
||||||
wsDuplex.on('close', () => {
|
wsDuplex.on('close', () => {
|
||||||
// we'll remove client connection which will in turn end() via our SocketBridge above
|
// we'll remove client connection which will in turn end() via our SocketBridge above
|
||||||
|
|
Loading…
Reference in New Issue