Skip to content

Commit 42c35ae

Browse files
committed
Merge pull request #691 from minrk/firefox-ws-connection-close
handle 'upgrade' in comma-separated connection header
2 parents 554f59c + ec683b9 commit 42c35ae

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/http-proxy/common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
5353
if (!outgoing.agent) {
5454
outgoing.headers = outgoing.headers || {};
5555
if (typeof outgoing.headers.connection !== 'string'
56-
|| outgoing.headers.connection.toLowerCase() !== 'upgrade'
56+
|| ! /(^|,)\s*upgrade\s*($|,)/i.test(outgoing.headers.connection)
5757
) { outgoing.headers.connection = 'close'; }
5858
}
5959

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

+43
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,49 @@ describe('lib/http-proxy/common.js', function () {
5959
expect(outgoing.headers.connection).to.eql('upgrade');
6060
});
6161

62+
it('should not override agentless connection: contains upgrade', 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': 'keep-alive, upgrade'}, // this is what Firefox sets
74+
},
75+
{
76+
method : 'i',
77+
url : 'am',
78+
headers : {'pro':'xy','overwritten':false}
79+
});
80+
expect(outgoing.headers.connection).to.eql('keep-alive, upgrade');
81+
});
82+
83+
it('should override agentless connection: contains improper upgrade', function () {
84+
// sanity check on upgrade regex
85+
var outgoing = {};
86+
common.setupOutgoing(outgoing,
87+
{
88+
agent: undefined,
89+
target: {
90+
host : 'hey',
91+
hostname : 'how',
92+
socketPath: 'are',
93+
port : 'you',
94+
},
95+
headers: {'connection': 'keep-alive, not upgrade'},
96+
},
97+
{
98+
method : 'i',
99+
url : 'am',
100+
headers : {'pro':'xy','overwritten':false}
101+
});
102+
expect(outgoing.headers.connection).to.eql('close');
103+
});
104+
62105
it('should override agentless non-upgrade header to close', function () {
63106
var outgoing = {};
64107
common.setupOutgoing(outgoing,

0 commit comments

Comments
 (0)