• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto) { common.skip('missing crypto'); }
4
5// Check for:
6// Spaced headers
7// Pseudo headers
8// Capitalized headers
9
10const http2 = require('http2');
11const { throws, strictEqual } = require('assert');
12
13{
14  const server = http2.createServer(common.mustCall((req, res) => {
15    throws(() => {
16      res.setHeader(':path', '/');
17    }, {
18      code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
19    });
20    throws(() => {
21      res.setHeader('t est', 123);
22    }, {
23      code: 'ERR_INVALID_HTTP_TOKEN'
24    });
25    res.setHeader('TEST', 123);
26    res.setHeader('test_', 123);
27    res.setHeader(' test', 123);
28    res.end();
29  }));
30
31  server.listen(0, common.mustCall(() => {
32    const session = http2.connect(`http://localhost:${server.address().port}`);
33    session.request({ 'test_': 123, 'TEST': 123 })
34      .on('end', common.mustCall(() => {
35        session.close();
36        server.close();
37      }));
38  }));
39}
40
41{
42  const server = http2.createServer();
43  server.listen(0, common.mustCall(() => {
44    const session = http2.connect(`http://localhost:${server.address().port}`);
45    session.on('error', common.mustCall((e) => {
46      strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
47      server.close();
48    }));
49    throws(() => {
50      session.request({ 't est': 123 });
51    }, {
52      code: 'ERR_INVALID_HTTP_TOKEN'
53    });
54  }));
55}
56
57
58{
59  const server = http2.createServer();
60  server.listen(0, common.mustCall(() => {
61    const session = http2.connect(`http://localhost:${server.address().port}`);
62    session.on('error', common.mustCall((e) => {
63      strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
64      server.close();
65    }));
66    throws(() => {
67      session.request({ ' test': 123 });
68    }, {
69      code: 'ERR_INVALID_HTTP_TOKEN'
70    });
71  }));
72}
73
74{
75  const server = http2.createServer();
76  server.listen(0, common.mustCall(() => {
77    const session4 = http2.connect(`http://localhost:${server.address().port}`);
78    throws(() => {
79      session4.request({ ':test': 123 });
80    }, {
81      code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
82    });
83    session4.close();
84    server.close();
85  }));
86}
87