-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: preserve raw header duplicates in writeHead after setHeader calls
writeHead accepts a raw header array, which is intended to allow directly specifying raw header details, such as ordering, duplicates and header key casing. When used by itself this works correctly. However, if setHeader was called first, it effectively changed the behaviour of subsequent writeHead calls, so that even if a raw header array was provided, duplicates were collapsed, losing raw header data. This change preserves the raw headers passed to writeHead, while still maintaining the 'writeHead overwrites setHeader' behaviour. PR-URL: #50394 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const Countdown = require('../common/countdown'); | ||
const assert = require('assert'); | ||
const { createServer, request } = require('http'); | ||
|
||
const server = createServer(common.mustCall((req, res) => { | ||
if (req.url.includes('setHeader')) { | ||
res.setHeader('set-val', 'abc'); | ||
} | ||
|
||
res.writeHead(200, [ | ||
'array-val', '1', | ||
'array-val', '2', | ||
]); | ||
|
||
res.end(); | ||
}, 2)); | ||
|
||
const countdown = new Countdown(2, () => server.close()); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
request({ | ||
port: server.address().port | ||
}, common.mustCall((res) => { | ||
assert.deepStrictEqual(res.rawHeaders.slice(0, 4), [ | ||
'array-val', '1', | ||
'array-val', '2', | ||
]); | ||
|
||
countdown.dec(); | ||
})).end(); | ||
|
||
request({ | ||
port: server.address().port, | ||
path: '/?setHeader' | ||
}, common.mustCall((res) => { | ||
assert.deepStrictEqual(res.rawHeaders.slice(0, 6), [ | ||
'set-val', 'abc', | ||
'array-val', '1', | ||
'array-val', '2', | ||
]); | ||
|
||
countdown.dec(); | ||
})).end(); | ||
})); |