[api] Update request event to be consistent by emitting both req and res. Add x-forwarded-for header.

This commit is contained in:
indexzero 2011-04-15 20:43:22 -04:00
parent c485c8742c
commit a3cb527be5

View File

@ -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.
//