mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[api] Update request event to be consistent by emitting both req and res. Add x-forwarded-for header.
This commit is contained in:
parent
c485c8742c
commit
a3cb527be5
@ -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.
|
||||
//
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user