copy headers instead of referencing them so they don't unexpectedly get overwritten

This commit is contained in:
Ricky Miller 2014-11-13 04:37:45 +09:00
parent 69a693034e
commit daa2ce0ee3
2 changed files with 5 additions and 6 deletions

View File

@ -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);

View File

@ -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);
});