From 0eb4917ded952a469057d0d925c1393fc3b7af02 Mon Sep 17 00:00:00 2001 From: indexzero Date: Sat, 10 Sep 2011 06:57:51 -0400 Subject: [PATCH] [fix] Add `x-forward-*` headers for WebSocket requests. Closes #74 --- lib/node-http-proxy/http-proxy.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 165fccf..9b4ef59 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -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: