node/test/parallel/test-http2-single-headers.js
davidmarkclements ef07d6570f errors: change ERR_HTTP2_HEADER_SINGLE_VALUE to TypeError
changes the base instance for ERR_HTTP2_HEADER_SINGLE_VALUE
from Error to TypeError as a more accurate representation
of the error. Additionally corrects the grammar of the error
message.

PR-URL: https://github.com/nodejs/node/pull/19805
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-04-09 13:29:48 +02:00

52 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const server = http2.createServer();
// Each of these headers must appear only once
const singles = [
'content-type',
'user-agent',
'referer',
'authorization',
'proxy-authorization',
'if-modified-since',
'if-unmodified-since',
'from',
'location',
'max-forwards'
];
server.on('stream', common.mustNotCall());
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
singles.forEach((i) => {
common.expectsError(
() => client.request({ [i]: 'abc', [i.toUpperCase()]: 'xyz' }),
{
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
type: TypeError,
message: `Header field "${i}" must only have a single value`
}
);
common.expectsError(
() => client.request({ [i]: ['abc', 'xyz'] }),
{
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
type: TypeError,
message: `Header field "${i}" must only have a single value`
}
);
});
server.close();
client.close();
}));