1'use strict';
2const common = require('../common');
3if (!common.hasCrypto) { common.skip('missing crypto'); }
4const assert = require('assert');
5const http2 = require('http2');
6
7const server1 = http2.createServer();
8
9server1.listen(0, common.mustCall(() => {
10  const session = http2.connect(`http://localhost:${server1.address().port}`);
11  // Check for req headers
12  assert.throws(() => {
13    session.request({ 'no underscore': 123 });
14  }, {
15    code: 'ERR_INVALID_HTTP_TOKEN'
16  });
17  session.on('error', common.mustCall((e) => {
18    assert.strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
19    server1.close();
20  }));
21}));
22
23const server2 = http2.createServer(common.mustCall((req, res) => {
24  // check for setHeader
25  assert.throws(() => {
26    res.setHeader('x y z', 123);
27  }, {
28    code: 'ERR_INVALID_HTTP_TOKEN'
29  });
30  res.end();
31}));
32
33server2.listen(0, common.mustCall(() => {
34  const session = http2.connect(`http://localhost:${server2.address().port}`);
35  const req = session.request();
36  req.on('end', common.mustCall(() => {
37    session.close();
38    server2.close();
39  }));
40}));
41
42const server3 = http2.createServer(common.mustCall((req, res) => {
43  // check for writeHead
44  assert.throws(common.mustCall(() => {
45    res.writeHead(200, {
46      'an invalid header': 123
47    });
48  }), {
49    code: 'ERR_INVALID_HTTP_TOKEN'
50  });
51  res.end();
52}));
53
54server3.listen(0, common.mustCall(() => {
55  const session = http2.connect(`http://localhost:${server3.address().port}`);
56  const req = session.request();
57  req.on('end', common.mustCall(() => {
58    server3.close();
59    session.close();
60  }));
61}));
62