mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 09:02:40 +00:00

writeHead supports an array of arrays containing header name and values. Compatibility between http2 & http1 even though this is not documented. Fixes: https://github.com/nodejs/node/issues/24466 PR-URL: https://github.com/nodejs/node/pull/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>
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
'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();
|
|
}));
|
|
}));
|