11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto) { common.skip('missing crypto'); }
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst http2 = require('http2');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst server1 = http2.createServer();
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciserver1.listen(0, common.mustCall(() => {
101cb0ef41Sopenharmony_ci  const session = http2.connect(`http://localhost:${server1.address().port}`);
111cb0ef41Sopenharmony_ci  // Check for req headers
121cb0ef41Sopenharmony_ci  assert.throws(() => {
131cb0ef41Sopenharmony_ci    session.request({ 'no underscore': 123 });
141cb0ef41Sopenharmony_ci  }, {
151cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_HTTP_TOKEN'
161cb0ef41Sopenharmony_ci  });
171cb0ef41Sopenharmony_ci  session.on('error', common.mustCall((e) => {
181cb0ef41Sopenharmony_ci    assert.strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
191cb0ef41Sopenharmony_ci    server1.close();
201cb0ef41Sopenharmony_ci  }));
211cb0ef41Sopenharmony_ci}));
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciconst server2 = http2.createServer(common.mustCall((req, res) => {
241cb0ef41Sopenharmony_ci  // check for setHeader
251cb0ef41Sopenharmony_ci  assert.throws(() => {
261cb0ef41Sopenharmony_ci    res.setHeader('x y z', 123);
271cb0ef41Sopenharmony_ci  }, {
281cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_HTTP_TOKEN'
291cb0ef41Sopenharmony_ci  });
301cb0ef41Sopenharmony_ci  res.end();
311cb0ef41Sopenharmony_ci}));
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciserver2.listen(0, common.mustCall(() => {
341cb0ef41Sopenharmony_ci  const session = http2.connect(`http://localhost:${server2.address().port}`);
351cb0ef41Sopenharmony_ci  const req = session.request();
361cb0ef41Sopenharmony_ci  req.on('end', common.mustCall(() => {
371cb0ef41Sopenharmony_ci    session.close();
381cb0ef41Sopenharmony_ci    server2.close();
391cb0ef41Sopenharmony_ci  }));
401cb0ef41Sopenharmony_ci}));
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ciconst server3 = http2.createServer(common.mustCall((req, res) => {
431cb0ef41Sopenharmony_ci  // check for writeHead
441cb0ef41Sopenharmony_ci  assert.throws(common.mustCall(() => {
451cb0ef41Sopenharmony_ci    res.writeHead(200, {
461cb0ef41Sopenharmony_ci      'an invalid header': 123
471cb0ef41Sopenharmony_ci    });
481cb0ef41Sopenharmony_ci  }), {
491cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_HTTP_TOKEN'
501cb0ef41Sopenharmony_ci  });
511cb0ef41Sopenharmony_ci  res.end();
521cb0ef41Sopenharmony_ci}));
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ciserver3.listen(0, common.mustCall(() => {
551cb0ef41Sopenharmony_ci  const session = http2.connect(`http://localhost:${server3.address().port}`);
561cb0ef41Sopenharmony_ci  const req = session.request();
571cb0ef41Sopenharmony_ci  req.on('end', common.mustCall(() => {
581cb0ef41Sopenharmony_ci    server3.close();
591cb0ef41Sopenharmony_ci    session.close();
601cb0ef41Sopenharmony_ci  }));
611cb0ef41Sopenharmony_ci}));
62