0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http2-compat-serverresponse-writehead-array.js
Tim Perry c25878d370
http2: add h2 compat support for appendHeader
PR-URL: https://github.com/nodejs/node/pull/51412
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-01-12 16:09:57 +00:00

97 lines
2.7 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
// Http2ServerResponse.writeHead should support arrays and nested arrays
{
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const port = server.address().port;
server.once('request', common.mustCall((request, response) => {
const returnVal = response.writeHead(200, [
['foo', 'bar'],
['foo', 'baz'],
['ABC', 123],
]);
assert.strictEqual(returnVal, response);
response.end(common.mustCall(() => { server.close(); }));
}));
const client = http2.connect(`http://localhost:${port}`, common.mustCall(() => {
const request = client.request();
request.on('response', common.mustCall((headers) => {
assert.strictEqual(headers.foo, 'bar, baz');
assert.strictEqual(headers.abc, '123');
assert.strictEqual(headers[':status'], 200);
}, 1));
request.on('end', common.mustCall(() => {
client.close();
}));
request.end();
request.resume();
}));
}));
}
{
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const port = server.address().port;
server.once('request', common.mustCall((request, response) => {
const returnVal = response.writeHead(200, ['foo', 'bar', 'foo', 'baz', 'ABC', 123]);
assert.strictEqual(returnVal, response);
response.end(common.mustCall(() => { server.close(); }));
}));
const client = http2.connect(`http://localhost:${port}`, common.mustCall(() => {
const request = client.request();
request.on('response', common.mustCall((headers) => {
assert.strictEqual(headers.foo, 'bar, baz');
assert.strictEqual(headers.abc, '123');
assert.strictEqual(headers[':status'], 200);
}, 1));
request.on('end', common.mustCall(() => {
client.close();
}));
request.end();
request.resume();
}));
}));
}
{
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const port = server.address().port;
server.once('request', common.mustCall((request, response) => {
try {
response.writeHead(200, ['foo', 'bar', 'ABC', 123, 'extra']);
} catch (err) {
assert.strictEqual(err.code, 'ERR_INVALID_ARG_VALUE');
}
response.end(common.mustCall(() => { server.close(); }));
}));
const client = http2.connect(`http://localhost:${port}`, common.mustCall(() => {
const request = client.request();
request.on('end', common.mustCall(() => {
client.close();
}));
request.end();
request.resume();
}));
}));
}