Skip to content

Commit

Permalink
[api] Update request event to be consistent by emitting both req
Browse files Browse the repository at this point in the history
…and `res`. Add `x-forwarded-for` header.
  • Loading branch information
indexzero committed Apr 16, 2011
1 parent c485c87 commit a3cb527
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/node-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
//
Expand Down

0 comments on commit a3cb527

Please sign in to comment.