1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const http2 = require('http2'); 8 9const server = http2.createServer(); 10 11// Each of these headers must appear only once 12const singles = [ 13 'content-type', 14 'user-agent', 15 'referer', 16 'authorization', 17 'proxy-authorization', 18 'if-modified-since', 19 'if-unmodified-since', 20 'from', 21 'location', 22 'max-forwards', 23]; 24 25server.on('stream', common.mustNotCall()); 26 27server.listen(0, common.mustCall(() => { 28 const client = http2.connect(`http://localhost:${server.address().port}`); 29 30 singles.forEach((i) => { 31 assert.throws( 32 () => client.request({ [i]: 'abc', [i.toUpperCase()]: 'xyz' }), 33 { 34 code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', 35 name: 'TypeError', 36 message: `Header field "${i}" must only have a single value` 37 } 38 ); 39 40 assert.throws( 41 () => client.request({ [i]: ['abc', 'xyz'] }), 42 { 43 code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', 44 name: 'TypeError', 45 message: `Header field "${i}" must only have a single value` 46 } 47 ); 48 }); 49 50 server.close(); 51 client.close(); 52})); 53