• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// This test ensures that the Http2SecureServer and Http2Server
4// settings are updated when the setting object is valid.
5// When the setting object is invalid, this test ensures that
6// updateSettings throws an exception.
7
8const common = require('../common');
9if (!common.hasCrypto) { common.skip('missing crypto'); }
10const assert = require('assert');
11const http2 = require('http2');
12
13testUpdateSettingsWith({
14  server: http2.createSecureServer(),
15  newServerSettings: {
16    'headerTableSize': 1,
17    'initialWindowSize': 1,
18    'maxConcurrentStreams': 1,
19    'maxHeaderListSize': 1,
20    'maxFrameSize': 16385,
21    'enablePush': false,
22    'enableConnectProtocol': true
23  }
24});
25testUpdateSettingsWith({
26  server: http2.createServer(),
27  newServerSettings: {
28    'enablePush': false
29  }
30});
31
32function testUpdateSettingsWith({ server, newServerSettings }) {
33  const oldServerSettings = getServerSettings(server);
34  assert.notDeepStrictEqual(oldServerSettings, newServerSettings);
35  server.updateSettings(newServerSettings);
36  const updatedServerSettings = getServerSettings(server);
37  assert.deepStrictEqual(updatedServerSettings, { ...oldServerSettings,
38                                                  ...newServerSettings });
39  assert.throws(() => server.updateSettings(''), {
40    message: 'The "settings" argument must be of type object. ' +
41    'Received type string (\'\')',
42    code: 'ERR_INVALID_ARG_TYPE',
43    name: 'TypeError'
44  });
45  assert.throws(() => server.updateSettings({
46    'maxHeaderListSize': 'foo'
47  }), {
48    message: 'Invalid value for setting "maxHeaderListSize": foo',
49    code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
50    name: 'RangeError'
51  });
52}
53
54function getServerSettings(server) {
55  const options = Object
56                  .getOwnPropertySymbols(server)
57                  .find((s) => s.toString() === 'Symbol(options)');
58  return server[options].settings;
59}
60