Skip to content

Commit ce26590

Browse files
committed
http2: remove side effects from validateSettings
The function did not only validate the input so far but it also made a copy of the input object and returned that copy to the callee function. That copy was not necessary for all call sites and it was not obvious that the function did not only validate the input but that it also returned a copy of it. This makes sure the function does nothing more than validation and copying is happening in the callee function when required. PR-URL: #26809 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 28e2c37 commit ce26590

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/internal/http2/core.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ function pingCallback(cb) {
784784
// 6. enablePush must be a boolean
785785
// All settings are optional and may be left undefined
786786
const validateSettings = hideStackFrames((settings) => {
787-
settings = { ...settings };
787+
if (settings === undefined) return;
788788
assertWithinRange('headerTableSize',
789789
settings.headerTableSize,
790790
0, kMaxInt);
@@ -805,7 +805,6 @@ const validateSettings = hideStackFrames((settings) => {
805805
throw new ERR_HTTP2_INVALID_SETTING_VALUE('enablePush',
806806
settings.enablePush);
807807
}
808-
return settings;
809808
});
810809

811810
// Creates the internal binding.Http2Session handle for an Http2Session
@@ -1144,15 +1143,15 @@ class Http2Session extends EventEmitter {
11441143
if (this.destroyed)
11451144
throw new ERR_HTTP2_INVALID_SESSION();
11461145
assertIsObject(settings, 'settings');
1147-
settings = validateSettings(settings);
1146+
validateSettings(settings);
11481147

11491148
if (callback && typeof callback !== 'function')
11501149
throw new ERR_INVALID_CALLBACK();
11511150
debug(`Http2Session ${sessionName(this[kType])}: sending settings`);
11521151

11531152
this[kState].pendingAck++;
11541153

1155-
const settingsFn = submitSettings.bind(this, settings, callback);
1154+
const settingsFn = submitSettings.bind(this, { ...settings }, callback);
11561155
if (this.connecting) {
11571156
this.once('connect', settingsFn);
11581157
return;
@@ -2817,7 +2816,8 @@ function createServer(options, handler) {
28172816
// HTTP2-Settings header frame.
28182817
function getPackedSettings(settings) {
28192818
assertIsObject(settings, 'settings');
2820-
updateSettingsBuffer(validateSettings(settings));
2819+
validateSettings(settings);
2820+
updateSettingsBuffer({ ...settings });
28212821
return binding.packSettings();
28222822
}
28232823

0 commit comments

Comments
 (0)