Skip to content

Commit a3cb527

Browse files
committed
[api] Update request event to be consistent by emitting both req and res. Add x-forwarded-for header.
1 parent c485c87 commit a3cb527

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/node-http-proxy.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ exports.createServer = function () {
104104

105105
proxy = new HttpProxy(options);
106106
server = http.createServer(function (req, res) {
107-
proxy.emit('request', req, req.headers.host, req.url);
107+
proxy.emit('request', req, res, req.headers.host, req.url);
108108

109109
// If we were passed a callback to process the request
110110
// or response in some way, then call it.
@@ -276,6 +276,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
276276
host = location.host;
277277
}
278278

279+
//
280+
// Add `x-forwarded-for` header to availible client IP to apps behind proxy
281+
//
282+
req.headers['x-forwarded-for'] = req.connection.remoteAddress;
283+
279284
//
280285
// Emit the `start` event indicating that we have begun the proxy operation.
281286
//

0 commit comments

Comments
 (0)