GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: add updateSettings to both http2 servers · nodejs/node@2e25922

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • http2.md
  • lib/internal/http2
    • core.js
  • test/parallel
    • test-http2-update-settings.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/http2.md‎

Copy file name to clipboardExpand all lines: doc/api/http2.md
+26Lines changed: 26 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,19 @@ A value of `0` will disable the timeout behavior on incoming connections.
18781878
The socket timeout logic is set up on connection, so changing this
18791879
value only affects new connections to the server, not any existing connections.
18801880

1881+
#### `server.updateSettings([settings])`
1882+
<!-- YAML
1883+
added: REPLACEME
1884+
-->
1885+
1886+
* `settings` {HTTP/2 Settings Object}
1887+
1888+
Used to update the server with the provided settings.
1889+
1890+
Throws `ERR_HTTP2_INVALID_SETTING_VALUE` for invalid `settings` values.
1891+
1892+
Throws `ERR_INVALID_ARG_TYPE` for invalid `settings` argument.
1893+
18811894
### Class: `Http2SecureServer`
18821895
<!-- YAML
18831896
added: v8.4.0
@@ -2059,6 +2072,19 @@ A value of `0` will disable the timeout behavior on incoming connections.
20592072
The socket timeout logic is set up on connection, so changing this
20602073
value only affects new connections to the server, not any existing connections.
20612074

2075+
#### `server.updateSettings([settings])`
2076+
<!-- YAML
2077+
added: REPLACEME
2078+
-->
2079+
2080+
* `settings` {HTTP/2 Settings Object}
2081+
2082+
Used to update the server with the provided settings.
2083+
2084+
Throws `ERR_HTTP2_INVALID_SETTING_VALUE` for invalid `settings` values.
2085+
2086+
Throws `ERR_INVALID_ARG_TYPE` for invalid `settings` argument.
2087+
20622088
### `http2.createServer(options[, onRequestHandler])`
20632089
<!-- YAML
20642090
added: v8.4.0
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,6 +3011,12 @@ class Http2SecureServer extends TLSServer {
30113011
}
30123012
return this;
30133013
}
3014+
3015+
updateSettings(settings) {
3016+
assertIsObject(settings, 'settings');
3017+
validateSettings(settings);
3018+
this[kOptions].settings = { ...this[kOptions].settings, ...settings };
3019+
}
30143020
}
30153021

30163022
class Http2Server extends NETServer {
@@ -3033,6 +3039,12 @@ class Http2Server extends NETServer {
30333039
}
30343040
return this;
30353041
}
3042+
3043+
updateSettings(settings) {
3044+
assertIsObject(settings, 'settings');
3045+
validateSettings(settings);
3046+
this[kOptions].settings = { ...this[kOptions].settings, ...settings };
3047+
}
30363048
}
30373049

30383050
Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function(
Collapse file

‎test/parallel/test-http2-update-settings.js‎

Copy file name to clipboard
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
8+
const common = require('../common');
9+
if (!common.hasCrypto) { common.skip('missing crypto'); }
10+
const assert = require('assert');
11+
const http2 = require('http2');
12+
13+
testUpdateSettingsWith({
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+
});
25+
testUpdateSettingsWith({
26+
server: http2.createServer(),
27+
newServerSettings: {
28+
'enablePush': false
29+
}
30+
});
31+
32+
function 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+
54+
function getServerSettings(server) {
55+
const options = Object
56+
.getOwnPropertySymbols(server)
57+
.find((s) => s.toString() === 'Symbol(options)');
58+
return server[options].settings;
59+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.