@@ -328,6 +328,7 @@ HttpProxy.prototype.close = function () {
328
328
// options.host {string} Host of the proxy target.
329
329
// options.buffer {Object} Result from `httpProxy.buffer(req)`
330
330
// options.https {Object|boolean} Settings for https.
331
+ // options.allow_xforwarded_headers {boolean} Don't clobber x-forwarded headers to allow layered proxies.
331
332
//
332
333
HttpProxy . prototype . proxyRequest = function ( req , res , options ) {
333
334
var self = this , errState = false , location , outgoing , protocol , reverseProxy ;
@@ -340,6 +341,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
340
341
options = options || { } ;
341
342
options . host = options . host || this . target . host ;
342
343
options . port = options . port || this . target . port ;
344
+ options . allow_xforwarded_headers = options . allow_xforwarded_headers || false ;
343
345
344
346
//
345
347
// Check the proxy table for this instance to see if we need
@@ -379,9 +381,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
379
381
// * `x-forwarded-proto`: Protocol of the original request
380
382
// * `x-forwarded-port`: Port of the original request.
381
383
//
382
- req . headers [ 'x-forwarded-for' ] = req . connection . remoteAddress || req . connection . socket . remoteAddress ;
383
- req . headers [ 'x-forwarded-port' ] = req . connection . remotePort || req . connection . socket . remotePort ;
384
- req . headers [ 'x-forwarded-proto' ] = res . connection . pair ? 'https' : 'http' ;
384
+ if ( options . allow_xforwarded_headers == true ) {
385
+ req . headers [ 'x-forwarded-for' ] = req . connection . remoteAddress || req . connection . socket . remoteAddress ;
386
+ req . headers [ 'x-forwarded-port' ] = req . connection . remotePort || req . connection . socket . remotePort ;
387
+ req . headers [ 'x-forwarded-proto' ] = res . connection . pair ? 'https' : 'http' ;
388
+ }
385
389
386
390
//
387
391
// Emit the `start` event indicating that we have begun the proxy operation.
0 commit comments