GeezerVison is showing github.com — http2: correct behaviour for enablePush unpack · nodejs/node@2e421ff
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/core.js +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2535,7 +2535,7 @@ function getUnpackedSettings(buf, options = {}) { | 2535 | 2535 | settings.headerTableSize = value; | 2536 | 2536 | break; | 2537 | 2537 | case NGHTTP2_SETTINGS_ENABLE_PUSH: | 2538 | | - settings.enablePush = Boolean(value); | | 2538 | + settings.enablePush = value; | 2539 | 2539 | break; | 2540 | 2540 | case NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS: | 2541 | 2541 | settings.maxConcurrentStreams = value; | @@ -2557,6 +2557,9 @@ function getUnpackedSettings(buf, options = {}) { | 2557 | 2557 | assertWithinRange('headerTableSize', | 2558 | 2558 | settings.headerTableSize, | 2559 | 2559 | 0, 2 ** 32 - 1); | | 2560 | + assertWithinRange('enablePush', | | 2561 | + settings.enablePush, | | 2562 | + 0, 1); | 2560 | 2563 | assertWithinRange('initialWindowSize', | 2561 | 2564 | settings.initialWindowSize, | 2562 | 2565 | 0, 2 ** 32 - 1); | @@ -2569,13 +2572,10 @@ function getUnpackedSettings(buf, options = {}) { | 2569 | 2572 | assertWithinRange('maxHeaderListSize', | 2570 | 2573 | settings.maxHeaderListSize, | 2571 | 2574 | 0, 2 ** 32 - 1); | 2572 | | - if (settings.enablePush !== undefined && | 2573 | | - typeof settings.enablePush !== 'boolean') { | 2574 | | - const err = new errors.TypeError('ERR_HTTP2_INVALID_SETTING_VALUE', | 2575 | | - 'enablePush', settings.enablePush); | 2576 | | - err.actual = settings.enablePush; | 2577 | | - throw err; | 2578 | | - } | | 2575 | + } | | 2576 | + | | 2577 | + if (settings.enablePush !== undefined) { | | 2578 | + settings.enablePush = !!settings.enablePush; | 2579 | 2579 | } | 2580 | 2580 |
| 2581 | 2581 | return settings; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http2-getpackedsettings.js +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -126,6 +126,27 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false })); | 126 | 126 | assert.strictEqual(settings.enablePush, true); | 127 | 127 | } | 128 | 128 |
| | 129 | +//should throw if enablePush is not 0 or 1 | | 130 | +{ | | 131 | + const packed = Buffer.from([ | | 132 | + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00]); | | 133 | + | | 134 | + const settings = http2.getUnpackedSettings(packed, { validate: true }); | | 135 | + assert.strictEqual(settings.enablePush, false); | | 136 | +} | | 137 | +{ | | 138 | + const packed = Buffer.from([ | | 139 | + 0x00, 0x02, 0x00, 0x00, 0x00, 0x64]); | | 140 | + | | 141 | + assert.throws(() => { | | 142 | + http2.getUnpackedSettings(packed, { validate: true }); | | 143 | + }, common.expectsError({ | | 144 | + code: 'ERR_HTTP2_INVALID_SETTING_VALUE', | | 145 | + type: RangeError, | | 146 | + message: 'Invalid value for setting "enablePush": 100' | | 147 | + })); | | 148 | +} | | 149 | + | 129 | 150 | //check for what happens if passing {validate: true} and no errors happen | 130 | 151 | { | 131 | 152 | const packed = Buffer.from([ | |
|