-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: add updateSettings to both http2 servers
Allow the user to update the server settings after using http2.createSecureServer() or after using http2.createServer(). Fixes: #35353 PR-URL: #35383 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'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 | ||
} | ||
}); | ||
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; | ||
} |