summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-invalidheaderfield.js
blob: 0544113f0bd7a7ef62de0b949ab991da8eb326bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
const common = require('../common');
if (!common.hasCrypto) { common.skip('missing crypto'); }

// Check for:
// Spaced headers
// Psuedo headers
// Capitalized headers

const http2 = require('http2');
const { throws, strictEqual } = require('assert');

{
  const server = http2.createServer(common.mustCall((req, res) => {
    throws(() => {
      res.setHeader(':path', '/');
    }, {
      code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
    });
    throws(() => {
      res.setHeader('t est', 123);
    }, {
      code: 'ERR_INVALID_HTTP_TOKEN'
    });
    res.setHeader('TEST', 123);
    res.setHeader('test_', 123);
    res.setHeader(' test', 123);
    res.end();
  }));

  server.listen(0, common.mustCall(() => {
    const session = http2.connect(`http://localhost:${server.address().port}`);
    session.request({ 'test_': 123, 'TEST': 123 })
      .on('end', common.mustCall(() => {
        session.close();
        server.close();
      }));
  }));
}

{
  const server = http2.createServer();
  server.listen(0, common.mustCall(() => {
    const session = http2.connect(`http://localhost:${server.address().port}`);
    session.on('error', common.mustCall((e) => {
      strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
      server.close();
    }));
    throws(() => {
      session.request({ 't est': 123 });
    }, {
      code: 'ERR_INVALID_HTTP_TOKEN'
    });
  }));
}


{
  const server = http2.createServer();
  server.listen(0, common.mustCall(() => {
    const session = http2.connect(`http://localhost:${server.address().port}`);
    session.on('error', common.mustCall((e) => {
      strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
      server.close();
    }));
    throws(() => {
      session.request({ ' test': 123 });
    }, {
      code: 'ERR_INVALID_HTTP_TOKEN'
    });
  }));
}

{
  const server = http2.createServer();
  server.listen(0, common.mustCall(() => {
    const session4 = http2.connect(`http://localhost:${server.address().port}`);
    throws(() => {
      session4.request({ ':test': 123 });
    }, {
      code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
    });
    session4.close();
    server.close();
  }));
}