Skip to content

Commit 0b16dfe

Browse files
mscdexMichael Scovetta
authored and
Michael Scovetta
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: nodejs#4456 PR-URL: nodejs#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 387d289 commit 0b16dfe

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
@@ -165,7 +165,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value, dest) {
165165

166166
default:
167167
// make comma-separated list
168-
if (dest[field] !== undefined) {
168+
if (typeof dest[field] === 'string') {
169169
dest[field] += ', ' + value;
170170
} else {
171171
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)