| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 50ec55c commit 6b08d00
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2498,6 +2498,11 @@ changes: | |||
| 2498 | 2498 | **Default:** `100`. | |
| 2499 | 2499 | * `settings` {HTTP/2 Settings Object} The initial settings to send to the | |
| 2500 | 2500 | remote peer upon connection. | |
| 2501 | + * `remoteCustomSettings` {Array} The array of integer values determines the | ||
| 2502 | + settings types, which are included in the `CustomSettings`-property of | ||
| 2503 | + the received remoteSettings. Please see the `CustomSettings`-property of | ||
| 2504 | + the `Http2Settings` object for more information, | ||
| 2505 | + on the allowed setting types. | ||
| 2501 | 2506 | * `Http1IncomingMessage` {http.IncomingMessage} Specifies the | |
| 2502 | 2507 | `IncomingMessage` class to used for HTTP/1 fallback. Useful for extending | |
| 2503 | 2508 | the original `http.IncomingMessage`. **Default:** `http.IncomingMessage`. | |
@@ -2652,6 +2657,10 @@ changes: | |||
| 2652 | 2657 | **Default:** `100`. | |
| 2653 | 2658 | * `settings` {HTTP/2 Settings Object} The initial settings to send to the | |
| 2654 | 2659 | remote peer upon connection. | |
| 2660 | + * `remoteCustomSettings` {Array} The array of integer values determines the | ||
| 2661 | + settings types, which are included in the `customSettings`-property of the | ||
| 2662 | + received remoteSettings. Please see the `customSettings`-property of the | ||
| 2663 | + `Http2Settings` object for more information, on the allowed setting types. | ||
| 2655 | 2664 | * ...: Any [`tls.createServer()`][] options can be provided. For | |
| 2656 | 2665 | servers, the identity options (`pfx` or `key`/`cert`) are usually required. | |
| 2657 | 2666 | * `origins` {string\[]} An array of origin strings to send within an `ORIGIN` | |
@@ -2780,6 +2789,10 @@ changes: | |||
| 2780 | 2789 | `'https:'` | |
| 2781 | 2790 | * `settings` {HTTP/2 Settings Object} The initial settings to send to the | |
| 2782 | 2791 | remote peer upon connection. | |
| 2792 | + * `remoteCustomSettings` {Array} The array of integer values determines the | ||
| 2793 | + settings types, which are included in the `CustomSettings`-property of the | ||
| 2794 | + received remoteSettings. Please see the `CustomSettings`-property of the | ||
| 2795 | + `Http2Settings` object for more information, on the allowed setting types. | ||
| 2783 | 2796 | * `createConnection` {Function} An optional callback that receives the `URL` | |
| 2784 | 2797 | instance passed to `connect` and the `options` object, and returns any | |
| 2785 | 2798 | [`Duplex`][] stream that is to be used as the connection for this session. | |
@@ -3022,9 +3035,11 @@ properties. | |||
| 3022 | 3035 | it should be greater than 6, although it is not an error. | |
| 3023 | 3036 | The values need to be unsigned integers in the range from 0 to 2^32-1. | |
| 3024 | 3037 | Currently, a maximum of up 10 custom settings is supported. | |
| 3025 | - It is only supported for sending SETTINGS. | ||
| 3026 | - Custom settings are not supported for the functions retrieving remote and | ||
| 3027 | - local settings as nghttp2 does not pass unknown HTTP/2 settings to Node.js. | ||
| 3038 | + It is only supported for sending SETTINGS, or for receiving settings values | ||
| 3039 | + specified in the `remoteCustomSettings` options of the server or client | ||
| 3040 | + object. Do not mix the `customSettings`-mechanism for a settings id with | ||
| 3041 | + interfaces for the natively handled settings, in case a setting becomes | ||
| 3042 | + natively supported in a future node version. | ||
| 3028 | 3043 | ||
| 3029 | 3044 | All additional properties on the settings object are ignored. | |
| 3030 | 3045 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,9 +9,11 @@ const { | |||
| 9 | 9 | FunctionPrototypeBind, | |
| 10 | 10 | FunctionPrototypeCall, | |
| 11 | 11 | MathMin, | |
| 12 | + Number, | ||
| 12 | 13 | ObjectAssign, | |
| 13 | 14 | ObjectKeys, | |
| 14 | 15 | ObjectDefineProperty, | |
| 16 | + ObjectEntries, | ||
| 15 | 17 | ObjectPrototypeHasOwnProperty, | |
| 16 | 18 | Promise, | |
| 17 | 19 | PromisePrototypeThen, | |
@@ -105,6 +107,7 @@ const { | |||
| 105 | 107 | ERR_HTTP2_STREAM_CANCEL, | |
| 106 | 108 | ERR_HTTP2_STREAM_ERROR, | |
| 107 | 109 | ERR_HTTP2_STREAM_SELF_DEPENDENCY, | |
| 110 | + ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS, | ||
| 108 | 111 | ERR_HTTP2_TRAILERS_ALREADY_SENT, | |
| 109 | 112 | ERR_HTTP2_TRAILERS_NOT_READY, | |
| 110 | 113 | ERR_HTTP2_UNSUPPORTED_PROTOCOL, | |
@@ -140,6 +143,7 @@ const { | |||
| 140 | 143 | ||
| 141 | 144 | const { | |
| 142 | 145 | assertIsObject, | |
| 146 | + assertIsArray, | ||
| 143 | 147 | assertValidPseudoHeader, | |
| 144 | 148 | assertValidPseudoHeaderResponse, | |
| 145 | 149 | assertValidPseudoHeaderTrailer, | |
@@ -155,7 +159,9 @@ const { | |||
| 155 | 159 | kRequest, | |
| 156 | 160 | kProxySocket, | |
| 157 | 161 | mapToHeaders, | |
| 162 | + MAX_ADDITIONAL_SETTINGS, | ||
| 158 | 163 | NghttpError, | |
| 164 | + remoteCustomSettingsToBuffer, | ||
| 159 | 165 | sessionName, | |
| 160 | 166 | toHeaderObject, | |
| 161 | 167 | updateOptionsBuffer, | |
@@ -947,6 +953,15 @@ function pingCallback(cb) { | |||
| 947 | 953 | const validateSettings = hideStackFrames((settings) => { | |
| 948 | 954 | if (settings === undefined) return; | |
| 949 | 955 | assertIsObject.withoutStackTrace(settings.customSettings, 'customSettings', 'Number'); | |
| 956 | + if (settings.customSettings) { | ||
| 957 | + const entries = ObjectEntries(settings.customSettings); | ||
| 958 | + if (entries.length > MAX_ADDITIONAL_SETTINGS) | ||
| 959 | + throw new ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS(); | ||
| 960 | + for (const { 0: key, 1: value } of entries) { | ||
| 961 | + assertWithinRange.withoutStackTrace('customSettings:id', Number(key), 0, 0xffff); | ||
| 962 | + assertWithinRange.withoutStackTrace('customSettings:value', Number(value), 0, kMaxInt); | ||
| 963 | + } | ||
| 964 | + } | ||
| 950 | 965 | ||
| 951 | 966 | assertWithinRange.withoutStackTrace('headerTableSize', | |
| 952 | 967 | settings.headerTableSize, | |
@@ -1031,6 +1046,9 @@ function setupHandle(socket, type, options) { | |||
| 1031 | 1046 | this[kState].flags |= SESSION_FLAGS_READY; | |
| 1032 | 1047 | ||
| 1033 | 1048 | updateOptionsBuffer(options); | |
| 1049 | + if (options.remoteCustomSettings) { | ||
| 1050 | + remoteCustomSettingsToBuffer(options.remoteCustomSettings); | ||
| 1051 | + } | ||
| 1034 | 1052 | const handle = new binding.Http2Session(type); | |
| 1035 | 1053 | handle[kOwner] = this; | |
| 1036 | 1054 | ||
@@ -3103,6 +3121,13 @@ function initializeOptions(options) { | |||
| 3103 | 3121 | assertIsObject(options.settings, 'options.settings'); | |
| 3104 | 3122 | options.settings = { ...options.settings }; | |
| 3105 | 3123 | ||
| 3124 | + assertIsArray(options.remoteCustomSettings, 'options.remoteCustomSettings'); | ||
| 3125 | + if (options.remoteCustomSettings) { | ||
| 3126 | + options.remoteCustomSettings = [ ...options.remoteCustomSettings ]; | ||
| 3127 | + if (options.remoteCustomSettings.length > MAX_ADDITIONAL_SETTINGS) | ||
| 3128 | + throw new ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS(); | ||
| 3129 | + } | ||
| 3130 | + | ||
| 3106 | 3131 | if (options.maxSessionInvalidFrames !== undefined) | |
| 3107 | 3132 | validateUint32(options.maxSessionInvalidFrames, 'maxSessionInvalidFrames'); | |
| 3108 | 3133 | ||
@@ -3277,6 +3302,13 @@ function connect(authority, options, listener) { | |||
| 3277 | 3302 | assertIsObject(options, 'options'); | |
| 3278 | 3303 | options = { ...options }; | |
| 3279 | 3304 | ||
| 3305 | + assertIsArray(options.remoteCustomSettings, 'options.remoteCustomSettings'); | ||
| 3306 | + if (options.remoteCustomSettings) { | ||
| 3307 | + options.remoteCustomSettings = [ ...options.remoteCustomSettings ]; | ||
| 3308 | + if (options.remoteCustomSettings.length > MAX_ADDITIONAL_SETTINGS) | ||
| 3309 | + throw new ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS(); | ||
| 3310 | + } | ||
| 3311 | + | ||
| 3280 | 3312 | if (typeof authority === 'string') | |
| 3281 | 3313 | authority = new URL(authority); | |
| 3282 | 3314 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -278,8 +278,19 @@ function updateOptionsBuffer(options) { | |||
| 278 | 278 | optionsBuffer[IDX_OPTIONS_FLAGS] = flags; | |
| 279 | 279 | } | |
| 280 | 280 | ||
| 281 | + function addCustomSettingsToObj() { | ||
| 282 | + const toRet = {}; | ||
| 283 | + const num = settingsBuffer[IDX_SETTINGS_FLAGS + 1]; | ||
| 284 | + for (let i = 0; i < num; i++) { | ||
| 285 | + toRet[settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * i + 1].toString()] = | ||
| 286 | + Number(settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * i + 2]); | ||
| 287 | + } | ||
| 288 | + return toRet; | ||
| 289 | + } | ||
| 290 | + | ||
| 281 | 291 | function getDefaultSettings() { | |
| 282 | 292 | settingsBuffer[IDX_SETTINGS_FLAGS] = 0; | |
| 293 | + settingsBuffer[IDX_SETTINGS_FLAGS + 1] = 0; // Length of custom settings | ||
| 283 | 294 | binding.refreshDefaultSettings(); | |
| 284 | 295 | const holder = { __proto__: null }; | |
| 285 | 296 | ||
@@ -327,6 +338,8 @@ function getDefaultSettings() { | |||
| 327 | 338 | settingsBuffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL] === 1; | |
| 328 | 339 | } | |
| 329 | 340 | ||
| 341 | + if (settingsBuffer[IDX_SETTINGS_FLAGS + 1]) holder.customSettings = addCustomSettingsToObj(); | ||
| 342 | + | ||
| 330 | 343 | return holder; | |
| 331 | 344 | } | |
| 332 | 345 | ||
@@ -338,7 +351,7 @@ function getSettings(session, remote) { | |||
| 338 | 351 | else | |
| 339 | 352 | session.localSettings(); | |
| 340 | 353 | ||
| 341 | - return { | ||
| 354 | + const toRet = { | ||
| 342 | 355 | headerTableSize: settingsBuffer[IDX_SETTINGS_HEADER_TABLE_SIZE], | |
| 343 | 356 | enablePush: !!settingsBuffer[IDX_SETTINGS_ENABLE_PUSH], | |
| 344 | 357 | initialWindowSize: settingsBuffer[IDX_SETTINGS_INITIAL_WINDOW_SIZE], | |
@@ -349,6 +362,8 @@ function getSettings(session, remote) { | |||
| 349 | 362 | enableConnectProtocol: | |
| 350 | 363 | !!settingsBuffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL], | |
| 351 | 364 | }; | |
| 365 | + if (settingsBuffer[IDX_SETTINGS_FLAGS + 1]) toRet.customSettings = addCustomSettingsToObj(); | ||
| 366 | + return toRet; | ||
| 352 | 367 | } | |
| 353 | 368 | ||
| 354 | 369 | function updateSettingsBuffer(settings) { | |
@@ -415,12 +430,22 @@ function updateSettingsBuffer(settings) { | |||
| 415 | 430 | } | |
| 416 | 431 | } | |
| 417 | 432 | if (!set) { // not supported | |
| 418 | - if (numCustomSettings === MAX_ADDITIONAL_SETTINGS) | ||
| 419 | - throw new ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS(); | ||
| 433 | + let i = 0; | ||
| 434 | + while (i < numCustomSettings) { | ||
| 435 | + if (settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * i + 1] === nsetting) { | ||
| 436 | + settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * i + 2] = val; | ||
| 437 | + break; | ||
| 438 | + } | ||
| 439 | + i++; | ||
| 440 | + } | ||
| 441 | + if (i === numCustomSettings) { | ||
| 442 | + if (numCustomSettings === MAX_ADDITIONAL_SETTINGS) | ||
| 443 | + throw new ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS(); | ||
| 420 | 444 | ||
| 421 | - settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * numCustomSettings + 1] = nsetting; | ||
| 422 | - settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * numCustomSettings + 2] = val; | ||
| 423 | - numCustomSettings++; | ||
| 445 | + settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * numCustomSettings + 1] = nsetting; | ||
| 446 | + settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * numCustomSettings + 2] = val; | ||
| 447 | + numCustomSettings++; | ||
| 448 | + } | ||
| 424 | 449 | } | |
| 425 | 450 | } | |
| 426 | 451 | } | |
@@ -475,6 +500,24 @@ function updateSettingsBuffer(settings) { | |||
| 475 | 500 | settingsBuffer[IDX_SETTINGS_FLAGS] = flags; | |
| 476 | 501 | } | |
| 477 | 502 | ||
| 503 | + function remoteCustomSettingsToBuffer(remoteCustomSettings) { | ||
| 504 | + if (remoteCustomSettings.length > MAX_ADDITIONAL_SETTINGS) | ||
| 505 | + throw new ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS(); | ||
| 506 | + let numCustomSettings = 0; | ||
| 507 | + for (let i = 0; i < remoteCustomSettings.length; i++) { | ||
| 508 | + const nsetting = remoteCustomSettings[i]; | ||
| 509 | + if (typeof nsetting === 'number' && nsetting <= 0xffff && | ||
| 510 | + nsetting >= 0) { | ||
| 511 | + settingsBuffer[IDX_SETTINGS_FLAGS + 1 + 2 * numCustomSettings + 1] = nsetting; | ||
| 512 | + numCustomSettings++; | ||
| 513 | + } else | ||
| 514 | + throw new ERR_HTTP2_INVALID_SETTING_VALUE.RangeError( | ||
| 515 | + 'Range Error', nsetting, 0, 0xffff); | ||
| 516 | + | ||
| 517 | + } | ||
| 518 | + settingsBuffer[IDX_SETTINGS_FLAGS + 1] = numCustomSettings; | ||
| 519 | + } | ||
| 520 | + | ||
| 478 | 521 | function getSessionState(session) { | |
| 479 | 522 | session.refreshState(); | |
| 480 | 523 | return { | |
@@ -649,6 +692,14 @@ const assertIsObject = hideStackFrames((value, name, types) => { | |||
| 649 | 692 | } | |
| 650 | 693 | }); | |
| 651 | 694 | ||
| 695 | + const assertIsArray = hideStackFrames((value, name, types) => { | ||
| 696 | + if (value !== undefined && | ||
| 697 | + (value === null || | ||
| 698 | + !ArrayIsArray(value))) { | ||
| 699 | + throw new ERR_INVALID_ARG_TYPE.HideStackFramesError(name, types || 'Array', value); | ||
| 700 | + } | ||
| 701 | + }); | ||
| 702 | + | ||
| 652 | 703 | const assertWithinRange = hideStackFrames( | |
| 653 | 704 | (name, value, min = 0, max = Infinity) => { | |
| 654 | 705 | if (value !== undefined && | |
@@ -732,6 +783,7 @@ function getAuthority(headers) { | |||
| 732 | 783 | ||
| 733 | 784 | module.exports = { | |
| 734 | 785 | assertIsObject, | |
| 786 | + assertIsArray, | ||
| 735 | 787 | assertValidPseudoHeader, | |
| 736 | 788 | assertValidPseudoHeaderResponse, | |
| 737 | 789 | assertValidPseudoHeaderTrailer, | |
@@ -747,7 +799,9 @@ module.exports = { | |||
| 747 | 799 | kProxySocket, | |
| 748 | 800 | kRequest, | |
| 749 | 801 | mapToHeaders, | |
| 802 | + MAX_ADDITIONAL_SETTINGS, | ||
| 750 | 803 | NghttpError, | |
| 804 | + remoteCustomSettingsToBuffer, | ||
| 751 | 805 | sessionName, | |
| 752 | 806 | toHeaderObject, | |
| 753 | 807 | updateOptionsBuffer, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments