• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6const assert = require('assert');
7const h2 = require('http2');
8const { inspect } = require('util');
9
10const server = h2.createServer();
11
12// We use the lower-level API here
13server.on('stream', common.mustCall((stream, headers, flags) => {
14  stream.respond();
15  stream.end('ok');
16}));
17server.on('session', common.mustCall((session) => {
18  session.on('remoteSettings', common.mustCall(2));
19}));
20
21server.listen(0, common.mustCall(() => {
22  const client = h2.connect(`http://localhost:${server.address().port}`);
23
24  [
25    ['headerTableSize', -1, RangeError],
26    ['headerTableSize', 2 ** 32, RangeError],
27    ['initialWindowSize', -1, RangeError],
28    ['initialWindowSize', 2 ** 32, RangeError],
29    ['maxFrameSize', 1, RangeError],
30    ['maxFrameSize', 2 ** 24, RangeError],
31    ['maxConcurrentStreams', -1, RangeError],
32    ['maxConcurrentStreams', 2 ** 32, RangeError],
33    ['maxHeaderListSize', -1, RangeError],
34    ['maxHeaderListSize', 2 ** 32, RangeError],
35    ['maxHeaderSize', -1, RangeError],
36    ['maxHeaderSize', 2 ** 32, RangeError],
37    ['enablePush', 'a', TypeError],
38    ['enablePush', 1, TypeError],
39    ['enablePush', 0, TypeError],
40    ['enablePush', null, TypeError],
41    ['enablePush', {}, TypeError],
42  ].forEach(([name, value, errorType]) =>
43    assert.throws(
44      () => client.settings({ [name]: value }),
45      {
46        code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
47        name: errorType.name
48      }
49    )
50  );
51
52  [1, true, {}, []].forEach((invalidCallback) =>
53    assert.throws(
54      () => client.settings({}, invalidCallback),
55      {
56        name: 'TypeError',
57        code: 'ERR_INVALID_CALLBACK',
58        message:
59          `Callback must be a function. Received ${inspect(invalidCallback)}`
60      }
61    )
62  );
63
64  client.settings({ maxFrameSize: 1234567 });
65
66  const req = client.request();
67  req.on('response', common.mustCall());
68  req.resume();
69  req.on('close', common.mustCall(() => {
70    server.close();
71    client.close();
72  }));
73}));
74