summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-client-settings-before-connect.js
blob: 961292d803ab7aea3a29570a723831bb431bbc68 (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
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');
const h2 = require('http2');
const { inspect } = require('util');

const server = h2.createServer();

// We use the lower-level API here
server.on('stream', common.mustCall((stream, headers, flags) => {
  stream.respond();
  stream.end('ok');
}));
server.on('session', common.mustCall((session) => {
  session.on('remoteSettings', common.mustCall(2));
}));

server.listen(0, common.mustCall(() => {
  const client = h2.connect(`http://localhost:${server.address().port}`);

  [
    ['headerTableSize', -1, RangeError],
    ['headerTableSize', 2 ** 32, RangeError],
    ['initialWindowSize', -1, RangeError],
    ['initialWindowSize', 2 ** 32, RangeError],
    ['maxFrameSize', 1, RangeError],
    ['maxFrameSize', 2 ** 24, RangeError],
    ['maxConcurrentStreams', -1, RangeError],
    ['maxConcurrentStreams', 2 ** 31, RangeError],
    ['maxHeaderListSize', -1, RangeError],
    ['maxHeaderListSize', 2 ** 32, RangeError],
    ['enablePush', 'a', TypeError],
    ['enablePush', 1, TypeError],
    ['enablePush', 0, TypeError],
    ['enablePush', null, TypeError],
    ['enablePush', {}, TypeError]
  ].forEach(([name, value, errorType]) =>
    common.expectsError(
      () => client.settings({ [name]: value }),
      {
        code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
        type: errorType
      }
    )
  );

  [1, true, {}, []].forEach((invalidCallback) =>
    common.expectsError(
      () => client.settings({}, invalidCallback),
      {
        type: TypeError,
        code: 'ERR_INVALID_CALLBACK',
        message:
          `Callback must be a function. Received ${inspect(invalidCallback)}`
      }
    )
  );

  client.settings({ maxFrameSize: 1234567 });

  const req = client.request();
  req.on('response', common.mustCall());
  req.resume();
  req.on('close', common.mustCall(() => {
    server.close();
    client.close();
  }));
}));