Skip to content

Commit 896ee7c

Browse files
committed
Merge pull request #640 from jayharris/master
Don't override connection header if Upgrading
2 parents c54278b + 8aa7c51 commit 896ee7c

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

lib/http-proxy/common.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
4747
outgoing.localAddress = options.localAddress;
4848

4949
//
50-
// Remark: If we are false set the connection: close. This is the right thing to do
50+
// Remark: If we are false and not upgrading, set the connection: close. This is the right thing to do
5151
// as node core doesn't handle this COMPLETELY properly yet.
5252
//
5353
if(!outgoing.agent) {
5454
outgoing.headers = outgoing.headers || {};
55-
outgoing.headers.connection = 'close';
55+
if(typeof outgoing.headers.connection !== 'string' || outgoing.headers.connection.toLowerCase() !== 'upgrade') {
56+
outgoing.headers.connection = 'close';
57+
}
5658
}
5759

5860
//

test/lib-http-proxy-common-test.js

+42
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,48 @@ describe('lib/http-proxy/common.js', function () {
3838
expect(outgoing.localAddress).to.eql('local.address');
3939
});
4040

41+
it('should not override agentless upgrade header', function () {
42+
var outgoing = {};
43+
common.setupOutgoing(outgoing,
44+
{
45+
agent: undefined,
46+
target: {
47+
host : 'hey',
48+
hostname : 'how',
49+
socketPath: 'are',
50+
port : 'you',
51+
},
52+
headers: {'connection': 'upgrade'},
53+
},
54+
{
55+
method : 'i',
56+
url : 'am',
57+
headers : {'pro':'xy','overwritten':false}
58+
});
59+
expect(outgoing.headers.connection).to.eql('upgrade');
60+
});
61+
62+
it('should override agentless non-upgrade header to close', function () {
63+
var outgoing = {};
64+
common.setupOutgoing(outgoing,
65+
{
66+
agent: undefined,
67+
target: {
68+
host : 'hey',
69+
hostname : 'how',
70+
socketPath: 'are',
71+
port : 'you',
72+
},
73+
headers: {'connection': 'xyz'},
74+
},
75+
{
76+
method : 'i',
77+
url : 'am',
78+
headers : {'pro':'xy','overwritten':false}
79+
});
80+
expect(outgoing.headers.connection).to.eql('close');
81+
});
82+
4183
it('should set the agent to false if none is given', function () {
4284
var outgoing = {};
4385
common.setupOutgoing(outgoing, {target:

0 commit comments

Comments
 (0)