2017-07-17 10:29:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2017-08-07 07:54:44 +02:00
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('missing crypto');
|
2019-12-25 18:02:16 +01:00
|
|
|
const assert = require('assert');
|
2017-07-17 10:29:42 -07:00
|
|
|
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',
|
2021-03-26 08:51:08 -07:00
|
|
|
'max-forwards',
|
2017-07-17 10:29:42 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
server.on('stream', common.mustNotCall());
|
|
|
|
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const client = http2.connect(`http://localhost:${server.address().port}`);
|
|
|
|
|
2023-11-11 08:22:16 -05:00
|
|
|
for (const i of singles) {
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(
|
2017-12-12 11:34:17 -08:00
|
|
|
() => client.request({ [i]: 'abc', [i.toUpperCase()]: 'xyz' }),
|
|
|
|
{
|
|
|
|
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2018-04-04 19:36:04 +02:00
|
|
|
message: `Header field "${i}" must only have a single value`
|
2017-12-12 11:34:17 -08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(
|
2017-12-12 11:34:17 -08:00
|
|
|
() => client.request({ [i]: ['abc', 'xyz'] }),
|
|
|
|
{
|
|
|
|
code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'TypeError',
|
2018-04-04 19:36:04 +02:00
|
|
|
message: `Header field "${i}" must only have a single value`
|
2017-12-12 11:34:17 -08:00
|
|
|
}
|
|
|
|
);
|
2023-11-11 08:22:16 -05:00
|
|
|
}
|
2017-07-17 10:29:42 -07:00
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
server.close();
|
|
|
|
client.close();
|
2017-07-17 10:29:42 -07:00
|
|
|
}));
|