0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http2-update-settings.js
Marten Richter 2c571c650a
http2: addtl http/2 settings
Currently, node.js http/2 is limited in sending SETTINGs,
that are currently implemented by nghttp2.
However, nghttp2 has the ability to send arbitary SETTINGs,
that are not known beforehand.
This patch adds this feature including a fall back mechanism,
if a SETTING is implemented in a later nghttp2 or node version.

Fixes: https://github.com/nodejs/node/issues/1337
PR-URL: https://github.com/nodejs/node/pull/49025
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-12-18 09:18:25 +00:00

61 lines
1.9 KiB
JavaScript

'use strict';
// This test ensures that the Http2SecureServer and Http2Server
// settings are updated when the setting object is valid.
// When the setting object is invalid, this test ensures that
// updateSettings throws an exception.
const common = require('../common');
if (!common.hasCrypto) { common.skip('missing crypto'); }
const assert = require('assert');
const http2 = require('http2');
testUpdateSettingsWith({
server: http2.createSecureServer(),
newServerSettings: {
'headerTableSize': 1,
'initialWindowSize': 1,
'maxConcurrentStreams': 1,
'maxHeaderListSize': 1,
'maxFrameSize': 16385,
'enablePush': false,
'enableConnectProtocol': true,
'customSettings': { '9999': 301 }
}
});
testUpdateSettingsWith({
server: http2.createServer(),
newServerSettings: {
'enablePush': false
}
});
function testUpdateSettingsWith({ server, newServerSettings }) {
const oldServerSettings = getServerSettings(server);
assert.notDeepStrictEqual(oldServerSettings, newServerSettings);
server.updateSettings(newServerSettings);
const updatedServerSettings = getServerSettings(server);
assert.deepStrictEqual(updatedServerSettings, { ...oldServerSettings,
...newServerSettings });
assert.throws(() => server.updateSettings(''), {
message: 'The "settings" argument must be of type object. ' +
'Received type string (\'\')',
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});
assert.throws(() => server.updateSettings({
'maxHeaderListSize': 'foo'
}), {
message: 'Invalid value for setting "maxHeaderListSize": foo',
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
name: 'RangeError'
});
}
function getServerSettings(server) {
const options = Object
.getOwnPropertySymbols(server)
.find((s) => s.toString() === 'Symbol(options)');
return server[options].settings;
}