11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst http2 = require('http2'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst server = http2.createServer(); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci// Each of these headers must appear only once 121cb0ef41Sopenharmony_ciconst singles = [ 131cb0ef41Sopenharmony_ci 'content-type', 141cb0ef41Sopenharmony_ci 'user-agent', 151cb0ef41Sopenharmony_ci 'referer', 161cb0ef41Sopenharmony_ci 'authorization', 171cb0ef41Sopenharmony_ci 'proxy-authorization', 181cb0ef41Sopenharmony_ci 'if-modified-since', 191cb0ef41Sopenharmony_ci 'if-unmodified-since', 201cb0ef41Sopenharmony_ci 'from', 211cb0ef41Sopenharmony_ci 'location', 221cb0ef41Sopenharmony_ci 'max-forwards', 231cb0ef41Sopenharmony_ci]; 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciserver.on('stream', common.mustNotCall()); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 281cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci singles.forEach((i) => { 311cb0ef41Sopenharmony_ci assert.throws( 321cb0ef41Sopenharmony_ci () => client.request({ [i]: 'abc', [i.toUpperCase()]: 'xyz' }), 331cb0ef41Sopenharmony_ci { 341cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', 351cb0ef41Sopenharmony_ci name: 'TypeError', 361cb0ef41Sopenharmony_ci message: `Header field "${i}" must only have a single value` 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci ); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci assert.throws( 411cb0ef41Sopenharmony_ci () => client.request({ [i]: ['abc', 'xyz'] }), 421cb0ef41Sopenharmony_ci { 431cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', 441cb0ef41Sopenharmony_ci name: 'TypeError', 451cb0ef41Sopenharmony_ci message: `Header field "${i}" must only have a single value` 461cb0ef41Sopenharmony_ci } 471cb0ef41Sopenharmony_ci ); 481cb0ef41Sopenharmony_ci }); 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci server.close(); 511cb0ef41Sopenharmony_ci client.close(); 521cb0ef41Sopenharmony_ci})); 53