Skip to content

Commit 421895f

Browse files
committed
[api] Add x-forwarded-proto and x-forwarded-port to proxied HTTP requests
1 parent e9b3ec9 commit 421895f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/node-http-proxy.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,16 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
344344
}
345345

346346
//
347-
// Add `x-forwarded-for` header to availible client IP to apps behind proxy
347+
// Add common proxy headers to the request so that they can
348+
// be availible to the proxy target server:
349+
//
350+
// * `x-forwarded-for`: IP Address of the original request
351+
// * `x-forwarded-proto`: Protocol of the original request
352+
// * `x-forwarded-port`: Port of the original request.
348353
//
349-
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
354+
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
355+
req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
356+
req.headers['x-forwarded-proto'] = res.connection.pair ? 'https' : 'http';
350357

351358
//
352359
// Emit the `start` event indicating that we have begun the proxy operation.

0 commit comments

Comments
 (0)