From daa2ce0ee300df72ca34b720ad3a15d9dfbbffc8 Mon Sep 17 00:00:00 2001 From: Ricky Miller Date: Thu, 13 Nov 2014 04:37:45 +0900 Subject: [PATCH 1/2] copy headers instead of referencing them so they don't unexpectedly get overwritten --- lib/http-proxy/common.js | 7 +++---- test/lib-http-proxy-common-test.js | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index 43919b1b5..06856f2ef 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -31,9 +31,8 @@ common.setupOutgoing = function(outgoing, options, req, forward) { function(e) { outgoing[e] = options[forward || 'target'][e]; } ); - ['method', 'headers'].forEach( - function(e) { outgoing[e] = req[e]; } - ); + outgoing.method = req.method + outgoing.headers = extend({},req.headers) if (options.headers){ extend(outgoing.headers, options.headers); @@ -141,7 +140,7 @@ common.urlJoin = function() { last = args[lastIndex], lastSegs = last.split('?'), retSegs; - + args[lastIndex] = lastSegs[0]; // diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index b74fd021f..c4edaf63a 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -146,7 +146,7 @@ describe('lib/http-proxy/common.js', function () { { method : 'i', url : 'am', - headers : 'proxy' + headers : {pro:'xy'} }); expect(outgoing.host).to.eql('how'); @@ -156,7 +156,7 @@ describe('lib/http-proxy/common.js', function () { expect(outgoing.method).to.eql('i'); expect(outgoing.path).to.eql('am'); - expect(outgoing.headers).to.eql('proxy') + expect(outgoing.headers.pro).to.eql('xy') expect(outgoing.port).to.eql(443); }); From 84036e9ddd1d4d925006c5438b3bcc0f17ba7a48 Mon Sep 17 00:00:00 2001 From: Ricky Miller Date: Thu, 13 Nov 2014 06:05:32 +0900 Subject: [PATCH 2/2] style changes --- lib/http-proxy/common.js | 4 ++-- test/lib-http-proxy-common-test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index 06856f2ef..a6aca80b0 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -31,8 +31,8 @@ common.setupOutgoing = function(outgoing, options, req, forward) { function(e) { outgoing[e] = options[forward || 'target'][e]; } ); - outgoing.method = req.method - outgoing.headers = extend({},req.headers) + outgoing.method = req.method; + outgoing.headers = extend({}, req.headers); if (options.headers){ extend(outgoing.headers, options.headers); diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index c4edaf63a..149c4226b 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -156,7 +156,7 @@ describe('lib/http-proxy/common.js', function () { expect(outgoing.method).to.eql('i'); expect(outgoing.path).to.eql('am'); - expect(outgoing.headers.pro).to.eql('xy') + expect(outgoing.headers.pro).to.eql('xy'); expect(outgoing.port).to.eql(443); });