Skip to content

Commit 0eb4917

Browse files
committed
[fix] Add x-forward-* headers for WebSocket requests. Closes #74
1 parent d6c5436 commit 0eb4917

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: lib/node-http-proxy/http-proxy.js

+14
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,20 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
351351
//
352352
return socket.destroy();
353353
}
354+
355+
//
356+
// Add common proxy headers to the request so that they can
357+
// be availible to the proxy target server:
358+
//
359+
// * `x-forwarded-for`: IP Address of the original request
360+
// * `x-forwarded-proto`: Protocol of the original request
361+
// * `x-forwarded-port`: Port of the original request.
362+
//
363+
if (this.enable.xforward && req.connection && req.connection.socket) {
364+
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
365+
req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
366+
req.headers['x-forwarded-proto'] = req.connection.pair ? 'https' : 'http';
367+
}
354368

355369
//
356370
// Helper function for setting appropriate socket values:

0 commit comments

Comments
 (0)