From c0c13a130309e3b2fd6b421b056dd024bd922d8e Mon Sep 17 00:00:00 2001 From: efokschaner Date: Thu, 28 May 2015 18:59:28 -0700 Subject: [PATCH 1/2] Don't overwrite global options Global options are being overwritten with every request causing per-request options to leak into the next call. --- lib/http-proxy/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/http-proxy/index.js b/lib/http-proxy/index.js index 7a5e1d2e8..1d91844f5 100644 --- a/lib/http-proxy/index.js +++ b/lib/http-proxy/index.js @@ -46,9 +46,9 @@ function createRightProxy(type) { args[cntr] !== res ) { //Copy global options - options = extend({}, options); + var requestOptions = extend({}, options); //Overwrite with request options - extend(options, args[cntr]); + extend(requestOptions, args[cntr]); cntr--; } @@ -60,11 +60,11 @@ function createRightProxy(type) { /* optional args parse end */ ['target', 'forward'].forEach(function(e) { - if (typeof options[e] === 'string') - options[e] = parse_url(options[e]); + if (typeof requestOptions[e] === 'string') + requestOptions[e] = parse_url(requestOptions[e]); }); - if (!options.target && !options.forward) { + if (!requestOptions.target && !requestOptions.forward) { return this.emit('error', new Error('Must provide a proper URL as target')); } @@ -77,7 +77,7 @@ function createRightProxy(type) { * refer to the connection socket * pass(req, socket, options, head) */ - if(passes[i](req, res, options, head, this, cbl)) { // passes can return a truthy value to halt the loop + if(passes[i](req, res, requestOptions, head, this, cbl)) { // passes can return a truthy value to halt the loop break; } } From 94c38f36bb1252d9b61a549a380decd8ba28d090 Mon Sep 17 00:00:00 2001 From: efokschaner Date: Thu, 28 May 2015 20:18:11 -0700 Subject: [PATCH 2/2] Make sure requestOptions is always available --- lib/http-proxy/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/http-proxy/index.js b/lib/http-proxy/index.js index 1d91844f5..77f409126 100644 --- a/lib/http-proxy/index.js +++ b/lib/http-proxy/index.js @@ -41,15 +41,14 @@ function createRightProxy(type) { cntr--; } + //Copy global options + var requestOptions = extend({}, options); if( !(args[cntr] instanceof Buffer) && args[cntr] !== res ) { - //Copy global options - var requestOptions = extend({}, options); //Overwrite with request options extend(requestOptions, args[cntr]); - cntr--; }