Skip to content

Commit 1bb2967

Browse files
mscdexMyles Borins
authored and
Myles Borins
committed
http: fix non-string header value concatenation
Since headers are stored in an empty literal object ({}) instead of an object created with Object.create(null), care must be taken with property names inherited from Object. Currently there are only functions inherited, so we can safely check for existing strings instead. Fixes: #4456 PR-URL: #4460 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 437d0e3 commit 1bb2967

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/_http_incoming.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value, dest) {
159159

160160
default:
161161
// make comma-separated list
162-
if (dest[field] !== undefined) {
162+
if (typeof dest[field] === 'string') {
163163
dest[field] += ', ' + value;
164164
} else {
165165
dest[field] = value;

test/parallel/test-http-server-multiheaders.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var srv = http.createServer(function(req, res) {
1616
assert.equal(req.headers['x-bar'], 'banjo, bango');
1717
assert.equal(req.headers['sec-websocket-protocol'], 'chat, share');
1818
assert.equal(req.headers['sec-websocket-extensions'], 'foo; 1, bar; 2, baz');
19+
assert.equal(req.headers['constructor'], 'foo, bar, baz');
1920

2021
res.writeHead(200, {'Content-Type' : 'text/plain'});
2122
res.end('EOF');
@@ -48,7 +49,10 @@ srv.listen(common.PORT, function() {
4849
['sec-websocket-protocol', 'share'],
4950
['sec-websocket-extensions', 'foo; 1'],
5051
['sec-websocket-extensions', 'bar; 2'],
51-
['sec-websocket-extensions', 'baz']
52+
['sec-websocket-extensions', 'baz'],
53+
['constructor', 'foo'],
54+
['constructor', 'bar'],
55+
['constructor', 'baz'],
5256
]
5357
});
5458
});

0 commit comments

Comments
 (0)