-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: add compat support for nested array headers
writeHead supports an array of arrays containing header name and values. Compatibility between http2 & http1 even though this is not documented. Fixes: #24466 PR-URL: #24665 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
1 parent
d5bf736
commit 61e0103
Showing
2 changed files
with
50 additions
and
2 deletions.
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
42 changes: 42 additions & 0 deletions
42
test/parallel/test-http2-compat-serverresponse-writehead-array.js
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,42 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const h2 = require('http2'); | ||
|
||
// Http2ServerResponse.writeHead should support nested arrays | ||
|
||
const server = h2.createServer(); | ||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
server.once('request', common.mustCall((request, response) => { | ||
response.writeHead(200, [ | ||
['foo', 'bar'], | ||
['ABC', 123] | ||
]); | ||
response.end(common.mustCall(() => { server.close(); })); | ||
})); | ||
|
||
const url = `http://localhost:${port}`; | ||
const client = h2.connect(url, common.mustCall(() => { | ||
const headers = { | ||
':path': '/', | ||
':method': 'GET', | ||
':scheme': 'http', | ||
':authority': `localhost:${port}` | ||
}; | ||
const request = client.request(headers); | ||
request.on('response', common.mustCall((headers) => { | ||
assert.strictEqual(headers.foo, 'bar'); | ||
assert.strictEqual(headers.abc, '123'); | ||
assert.strictEqual(headers[':status'], 200); | ||
}, 1)); | ||
request.on('end', common.mustCall(() => { | ||
client.close(); | ||
})); | ||
request.end(); | ||
request.resume(); | ||
})); | ||
})); |