Skip to content
Browse files

[api] Add `x-forwarded-proto` and `x-forwarded-port` to proxied HTTP …

…requests
  • Loading branch information...
1 parent e9b3ec9 commit 421895fa308d49628bbbb546d542efa96769c3f4 @indexzero indexzero committed May 19, 2011
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/node-http-proxy.js
View
11 lib/node-http-proxy.js
@@ -344,9 +344,16 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
}
//
- // Add `x-forwarded-for` header to availible client IP to apps behind proxy
+ // Add common proxy headers to the request so that they can
+ // be availible to the proxy target server:
+ //
+ // * `x-forwarded-for`: IP Address of the original request
+ // * `x-forwarded-proto`: Protocol of the original request
+ // * `x-forwarded-port`: Port of the original request.
//
- req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
+ req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
+ req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
+ req.headers['x-forwarded-proto'] = res.connection.pair ? 'https' : 'http';
//
// Emit the `start` event indicating that we have begun the proxy operation.

0 comments on commit 421895f

Please sign in to comment.
Something went wrong with that request. Please try again.