From a3cb527be5e42d5192400933bf32a361b8c707c4 Mon Sep 17 00:00:00 2001 From: indexzero Date: Fri, 15 Apr 2011 20:43:22 -0400 Subject: [PATCH] [api] Update `request` event to be consistent by emitting both `req` and `res`. Add `x-forwarded-for` header. --- lib/node-http-proxy.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index d9f2d15..3af5990 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -104,7 +104,7 @@ exports.createServer = function () { proxy = new HttpProxy(options); server = http.createServer(function (req, res) { - proxy.emit('request', req, req.headers.host, req.url); + proxy.emit('request', req, res, req.headers.host, req.url); // If we were passed a callback to process the request // or response in some way, then call it. @@ -276,6 +276,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) { host = location.host; } + // + // Add `x-forwarded-for` header to availible client IP to apps behind proxy + // + req.headers['x-forwarded-for'] = req.connection.remoteAddress; + // // Emit the `start` event indicating that we have begun the proxy operation. //