| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -659,6 +659,33 @@ function pingCallback(cb) { | |||
| 659 | 659 | }; | |
| 660 | 660 | } | |
| 661 | 661 | ||
| 662 | + function validateSettings(settings) { | ||
| 663 | + settings = Object.assign({}, settings); | ||
| 664 | + assertWithinRange('headerTableSize', | ||
| 665 | + settings.headerTableSize, | ||
| 666 | + 0, kMaxInt); | ||
| 667 | + assertWithinRange('initialWindowSize', | ||
| 668 | + settings.initialWindowSize, | ||
| 669 | + 0, kMaxInt); | ||
| 670 | + assertWithinRange('maxFrameSize', | ||
| 671 | + settings.maxFrameSize, | ||
| 672 | + 16384, kMaxFrameSize); | ||
| 673 | + assertWithinRange('maxConcurrentStreams', | ||
| 674 | + settings.maxConcurrentStreams, | ||
| 675 | + 0, kMaxStreams); | ||
| 676 | + assertWithinRange('maxHeaderListSize', | ||
| 677 | + settings.maxHeaderListSize, | ||
| 678 | + 0, kMaxInt); | ||
| 679 | + if (settings.enablePush !== undefined && | ||
| 680 | + typeof settings.enablePush !== 'boolean') { | ||
| 681 | + const err = new errors.TypeError('ERR_HTTP2_INVALID_SETTING_VALUE', | ||
| 682 | + 'enablePush', settings.enablePush); | ||
| 683 | + err.actual = settings.enablePush; | ||
| 684 | + throw err; | ||
| 685 | + } | ||
| 686 | + return settings; | ||
| 687 | + } | ||
| 688 | + | ||
| 662 | 689 | // Upon creation, the Http2Session takes ownership of the socket. The session | |
| 663 | 690 | // may not be ready to use immediately if the socket is not yet fully connected. | |
| 664 | 691 | class Http2Session extends EventEmitter { | |
@@ -842,29 +869,7 @@ class Http2Session extends EventEmitter { | |||
| 842 | 869 | ||
| 843 | 870 | // Validate the input first | |
| 844 | 871 | assertIsObject(settings, 'settings'); | |
| 845 | - settings = Object.assign(Object.create(null), settings); | ||
| 846 | - assertWithinRange('headerTableSize', | ||
| 847 | - settings.headerTableSize, | ||
| 848 | - 0, kMaxInt); | ||
| 849 | - assertWithinRange('initialWindowSize', | ||
| 850 | - settings.initialWindowSize, | ||
| 851 | - 0, kMaxInt); | ||
| 852 | - assertWithinRange('maxFrameSize', | ||
| 853 | - settings.maxFrameSize, | ||
| 854 | - 16384, kMaxFrameSize); | ||
| 855 | - assertWithinRange('maxConcurrentStreams', | ||
| 856 | - settings.maxConcurrentStreams, | ||
| 857 | - 0, kMaxStreams); | ||
| 858 | - assertWithinRange('maxHeaderListSize', | ||
| 859 | - settings.maxHeaderListSize, | ||
| 860 | - 0, kMaxInt); | ||
| 861 | - if (settings.enablePush !== undefined && | ||
| 862 | - typeof settings.enablePush !== 'boolean') { | ||
| 863 | - const err = new errors.TypeError('ERR_HTTP2_INVALID_SETTING_VALUE', | ||
| 864 | - 'enablePush', settings.enablePush); | ||
| 865 | - err.actual = settings.enablePush; | ||
| 866 | - throw err; | ||
| 867 | - } | ||
| 872 | + settings = validateSettings(settings); | ||
| 868 | 873 | if (state.pendingAck === state.maxPendingAck) { | |
| 869 | 874 | throw new errors.Error('ERR_HTTP2_MAX_PENDING_SETTINGS_ACK', | |
| 870 | 875 | this[kState].pendingAck); | |
@@ -2362,30 +2367,7 @@ function createServer(options, handler) { | |||
| 2362 | 2367 | // HTTP2-Settings header frame. | |
| 2363 | 2368 | function getPackedSettings(settings) { | |
| 2364 | 2369 | assertIsObject(settings, 'settings'); | |
| 2365 | - settings = settings || Object.create(null); | ||
| 2366 | - assertWithinRange('headerTableSize', | ||
| 2367 | - settings.headerTableSize, | ||
| 2368 | - 0, kMaxInt); | ||
| 2369 | - assertWithinRange('initialWindowSize', | ||
| 2370 | - settings.initialWindowSize, | ||
| 2371 | - 0, kMaxInt); | ||
| 2372 | - assertWithinRange('maxFrameSize', | ||
| 2373 | - settings.maxFrameSize, | ||
| 2374 | - 16384, kMaxFrameSize); | ||
| 2375 | - assertWithinRange('maxConcurrentStreams', | ||
| 2376 | - settings.maxConcurrentStreams, | ||
| 2377 | - 0, kMaxStreams); | ||
| 2378 | - assertWithinRange('maxHeaderListSize', | ||
| 2379 | - settings.maxHeaderListSize, | ||
| 2380 | - 0, kMaxInt); | ||
| 2381 | - if (settings.enablePush !== undefined && | ||
| 2382 | - typeof settings.enablePush !== 'boolean') { | ||
| 2383 | - const err = new errors.TypeError('ERR_HTTP2_INVALID_SETTING_VALUE', | ||
| 2384 | - 'enablePush', settings.enablePush); | ||
| 2385 | - err.actual = settings.enablePush; | ||
| 2386 | - throw err; | ||
| 2387 | - } | ||
| 2388 | - updateSettingsBuffer(settings); | ||
| 2370 | + updateSettingsBuffer(validateSettings(settings)); | ||
| 2389 | 2371 | return binding.packSettings(); | |
| 2390 | 2372 | } | |
| 2391 | 2373 | ||
@@ -2396,7 +2378,7 @@ function getUnpackedSettings(buf, options = {}) { | |||
| 2396 | 2378 | } | |
| 2397 | 2379 | if (buf.length % 6 !== 0) | |
| 2398 | 2380 | throw new errors.RangeError('ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH'); | |
| 2399 | - const settings = Object.create(null); | ||
| 2381 | + const settings = {}; | ||
| 2400 | 2382 | let offset = 0; | |
| 2401 | 2383 | while (offset < buf.length) { | |
| 2402 | 2384 | const id = buf.readUInt16BE(offset); | |
@@ -2407,7 +2389,7 @@ function getUnpackedSettings(buf, options = {}) { | |||
| 2407 | 2389 | settings.headerTableSize = value; | |
| 2408 | 2390 | break; | |
| 2409 | 2391 | case NGHTTP2_SETTINGS_ENABLE_PUSH: | |
| 2410 | - settings.enablePush = value; | ||
| 2392 | + settings.enablePush = value !== 0; | ||
| 2411 | 2393 | break; | |
| 2412 | 2394 | case NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS: | |
| 2413 | 2395 | settings.maxConcurrentStreams = value; | |
@@ -2425,30 +2407,8 @@ function getUnpackedSettings(buf, options = {}) { | |||
| 2425 | 2407 | offset += 4; | |
| 2426 | 2408 | } | |
| 2427 | 2409 | ||
| 2428 | - if (options != null && options.validate) { | ||
| 2429 | - assertWithinRange('headerTableSize', | ||
| 2430 | - settings.headerTableSize, | ||
| 2431 | - 0, kMaxInt); | ||
| 2432 | - assertWithinRange('enablePush', | ||
| 2433 | - settings.enablePush, | ||
| 2434 | - 0, 1); | ||
| 2435 | - assertWithinRange('initialWindowSize', | ||
| 2436 | - settings.initialWindowSize, | ||
| 2437 | - 0, kMaxInt); | ||
| 2438 | - assertWithinRange('maxFrameSize', | ||
| 2439 | - settings.maxFrameSize, | ||
| 2440 | - 16384, kMaxFrameSize); | ||
| 2441 | - assertWithinRange('maxConcurrentStreams', | ||
| 2442 | - settings.maxConcurrentStreams, | ||
| 2443 | - 0, kMaxStreams); | ||
| 2444 | - assertWithinRange('maxHeaderListSize', | ||
| 2445 | - settings.maxHeaderListSize, | ||
| 2446 | - 0, kMaxInt); | ||
| 2447 | - } | ||
| 2448 | - | ||
| 2449 | - if (settings.enablePush !== undefined) { | ||
| 2450 | - settings.enablePush = !!settings.enablePush; | ||
| 2451 | - } | ||
| 2410 | + if (options != null && options.validate) | ||
| 2411 | + validateSettings(settings); | ||
| 2452 | 2412 | ||
| 2453 | 2413 | return settings; | |
| 2454 | 2414 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,7 +128,6 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false })); | |||
| 128 | 128 | assert.strictEqual(settings.enablePush, true); | |
| 129 | 129 | } | |
| 130 | 130 | ||
| 131 | - //should throw if enablePush is not 0 or 1 | ||
| 132 | 131 | { | |
| 133 | 132 | const packed = Buffer.from([ | |
| 134 | 133 | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00]); | |
@@ -140,13 +139,8 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false })); | |||
| 140 | 139 | const packed = Buffer.from([ | |
| 141 | 140 | 0x00, 0x02, 0x00, 0x00, 0x00, 0x64]); | |
| 142 | 141 | ||
| 143 | - assert.throws(() => { | ||
| 144 | - http2.getUnpackedSettings(packed, { validate: true }); | ||
| 145 | - }, common.expectsError({ | ||
| 146 | - code: 'ERR_HTTP2_INVALID_SETTING_VALUE', | ||
| 147 | - type: RangeError, | ||
| 148 | - message: 'Invalid value for setting "enablePush": 100' | ||
| 149 | - })); | ||
| 142 | + const settings = http2.getUnpackedSettings(packed, { validate: true }); | ||
| 143 | + assert.strictEqual(settings.enablePush, true); | ||
| 150 | 144 | } | |
| 151 | 145 | ||
| 152 | 146 | //check for what happens if passing {validate: true} and no errors happen | |
| Back | FazBrowse Home | New Git URL |
0 commit comments