| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9bcef68 commit 43bf1f6
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1078,7 +1078,7 @@ changes: | |||
| 1078 | 1078 | `weight` option is deprecated. | |
| 1079 | 1079 | --> | |
| 1080 | 1080 | ||
| 1081 | - * `headers` {HTTP/2 Headers Object} | ||
| 1081 | + * `headers` {HTTP/2 Headers Object} | {Array} | ||
| 1082 | 1082 | ||
| 1083 | 1083 | * `options` {Object} | |
| 1084 | 1084 | * `endStream` {boolean} `true` if the `Http2Stream` _writable_ side should | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,6 @@ const { | |||
| 9 | 9 | ObjectDefineProperty, | |
| 10 | 10 | ObjectEntries, | |
| 11 | 11 | ObjectHasOwn, | |
| 12 | - ObjectKeys, | ||
| 13 | 12 | Promise, | |
| 14 | 13 | Proxy, | |
| 15 | 14 | ReflectApply, | |
@@ -47,10 +46,7 @@ const { Duplex } = require('stream'); | |||
| 47 | 46 | const tls = require('tls'); | |
| 48 | 47 | const { setImmediate, setTimeout, clearTimeout } = require('timers'); | |
| 49 | 48 | ||
| 50 | - const { | ||
| 51 | - kIncomingMessage, | ||
| 52 | - _checkIsHttpToken: checkIsHttpToken, | ||
| 53 | - } = require('_http_common'); | ||
| 49 | + const { kIncomingMessage } = require('_http_common'); | ||
| 54 | 50 | const { kServerResponse, Server: HttpServer, httpServerPreClose, setupConnectionsTracking } = require('_http_server'); | |
| 55 | 51 | const JSStreamSocket = require('internal/js_stream_socket'); | |
| 56 | 52 | ||
@@ -69,9 +65,6 @@ const { | |||
| 69 | 65 | codes: { | |
| 70 | 66 | ERR_HTTP2_ALTSVC_INVALID_ORIGIN, | |
| 71 | 67 | ERR_HTTP2_ALTSVC_LENGTH, | |
| 72 | - ERR_HTTP2_CONNECT_AUTHORITY, | ||
| 73 | - ERR_HTTP2_CONNECT_PATH, | ||
| 74 | - ERR_HTTP2_CONNECT_SCHEME, | ||
| 75 | 68 | ERR_HTTP2_GOAWAY_SESSION, | |
| 76 | 69 | ERR_HTTP2_HEADERS_AFTER_RESPOND, | |
| 77 | 70 | ERR_HTTP2_HEADERS_SENT, | |
@@ -109,7 +102,6 @@ const { | |||
| 109 | 102 | ERR_INVALID_ARG_TYPE, | |
| 110 | 103 | ERR_INVALID_ARG_VALUE, | |
| 111 | 104 | ERR_INVALID_CHAR, | |
| 112 | - ERR_INVALID_HTTP_TOKEN, | ||
| 113 | 105 | ERR_OUT_OF_RANGE, | |
| 114 | 106 | ERR_SOCKET_CLOSED, | |
| 115 | 107 | }, | |
@@ -138,23 +130,26 @@ const { | |||
| 138 | 130 | const { | |
| 139 | 131 | assertIsObject, | |
| 140 | 132 | assertIsArray, | |
| 141 | - assertValidPseudoHeader, | ||
| 142 | 133 | assertValidPseudoHeaderResponse, | |
| 143 | 134 | assertValidPseudoHeaderTrailer, | |
| 144 | 135 | assertWithinRange, | |
| 136 | + buildNgHeaderString, | ||
| 145 | 137 | getAuthority, | |
| 146 | 138 | getDefaultSettings, | |
| 147 | 139 | getSessionState, | |
| 148 | 140 | getSettings, | |
| 149 | 141 | getStreamState, | |
| 150 | 142 | isPayloadMeaningless, | |
| 143 | + kAuthority, | ||
| 151 | 144 | kSensitiveHeaders, | |
| 152 | 145 | kSocket, | |
| 153 | 146 | kRequest, | |
| 147 | + kProtocol, | ||
| 154 | 148 | kProxySocket, | |
| 155 | - mapToHeaders, | ||
| 156 | 149 | MAX_ADDITIONAL_SETTINGS, | |
| 157 | 150 | NghttpError, | |
| 151 | + prepareRequestHeadersArray, | ||
| 152 | + prepareRequestHeadersObject, | ||
| 158 | 153 | remoteCustomSettingsToBuffer, | |
| 159 | 154 | sessionName, | |
| 160 | 155 | toHeaderObject, | |
@@ -242,7 +237,6 @@ const NETServer = net.Server; | |||
| 242 | 237 | const TLSServer = tls.Server; | |
| 243 | 238 | ||
| 244 | 239 | const kAlpnProtocol = Symbol('alpnProtocol'); | |
| 245 | - const kAuthority = Symbol('authority'); | ||
| 246 | 240 | const kEncrypted = Symbol('encrypted'); | |
| 247 | 241 | const kID = Symbol('id'); | |
| 248 | 242 | const kInit = Symbol('init'); | |
@@ -254,7 +248,6 @@ const kOwner = owner_symbol; | |||
| 254 | 248 | const kOrigin = Symbol('origin'); | |
| 255 | 249 | const kPendingRequestCalls = Symbol('kPendingRequestCalls'); | |
| 256 | 250 | const kProceed = Symbol('proceed'); | |
| 257 | - const kProtocol = Symbol('protocol'); | ||
| 258 | 251 | const kRemoteSettings = Symbol('remote-settings'); | |
| 259 | 252 | const kRequestAsyncResource = Symbol('requestAsyncResource'); | |
| 260 | 253 | const kSentHeaders = Symbol('sent-headers'); | |
@@ -297,7 +290,6 @@ const { | |||
| 297 | 290 | HTTP2_HEADER_DATE, | |
| 298 | 291 | HTTP2_HEADER_METHOD, | |
| 299 | 292 | HTTP2_HEADER_PATH, | |
| 300 | - HTTP2_HEADER_PROTOCOL, | ||
| 301 | 293 | HTTP2_HEADER_SCHEME, | |
| 302 | 294 | HTTP2_HEADER_STATUS, | |
| 303 | 295 | HTTP2_HEADER_CONTENT_LENGTH, | |
@@ -312,7 +304,6 @@ const { | |||
| 312 | 304 | ||
| 313 | 305 | HTTP2_METHOD_GET, | |
| 314 | 306 | HTTP2_METHOD_HEAD, | |
| 315 | - HTTP2_METHOD_CONNECT, | ||
| 316 | 307 | ||
| 317 | 308 | HTTP_STATUS_CONTINUE, | |
| 318 | 309 | HTTP_STATUS_RESET_CONTENT, | |
@@ -1808,7 +1799,7 @@ class ClientHttp2Session extends Http2Session { | |||
| 1808 | 1799 | ||
| 1809 | 1800 | // Submits a new HTTP2 request to the connected peer. Returns the | |
| 1810 | 1801 | // associated Http2Stream instance. | |
| 1811 | - request(headers, options) { | ||
| 1802 | + request(headersParam, options) { | ||
| 1812 | 1803 | debugSessionObj(this, 'initiating request'); | |
| 1813 | 1804 | ||
| 1814 | 1805 | if (this.destroyed) | |
@@ -1819,62 +1810,61 @@ class ClientHttp2Session extends Http2Session { | |||
| 1819 | 1810 | ||
| 1820 | 1811 | this[kUpdateTimer](); | |
| 1821 | 1812 | ||
| 1822 | - if (headers !== null && headers !== undefined) { | ||
| 1823 | - const keys = ObjectKeys(headers); | ||
| 1824 | - for (let i = 0; i < keys.length; i++) { | ||
| 1825 | - const header = keys[i]; | ||
| 1826 | - if (header[0] === ':') { | ||
| 1827 | - assertValidPseudoHeader(header); | ||
| 1828 | - } else if (header && !checkIsHttpToken(header)) | ||
| 1829 | - this.destroy(new ERR_INVALID_HTTP_TOKEN('Header name', header)); | ||
| 1830 | - } | ||
| 1813 | + let headersList; | ||
| 1814 | + let headersObject; | ||
| 1815 | + let scheme; | ||
| 1816 | + let authority; | ||
| 1817 | + let method; | ||
| 1818 | + | ||
| 1819 | + if (ArrayIsArray(headersParam)) { | ||
| 1820 | + ({ | ||
| 1821 | + headersList, | ||
| 1822 | + scheme, | ||
| 1823 | + authority, | ||
| 1824 | + method, | ||
| 1825 | + } = prepareRequestHeadersArray(headersParam, this)); | ||
| 1826 | + } else if (!!headersParam && typeof headersParam === 'object') { | ||
| 1827 | + ({ | ||
| 1828 | + headersObject, | ||
| 1829 | + headersList, | ||
| 1830 | + scheme, | ||
| 1831 | + authority, | ||
| 1832 | + method, | ||
| 1833 | + } = prepareRequestHeadersObject(headersParam, this)); | ||
| 1834 | + } else if (headersParam === undefined) { | ||
| 1835 | + ({ | ||
| 1836 | + headersObject, | ||
| 1837 | + headersList, | ||
| 1838 | + scheme, | ||
| 1839 | + authority, | ||
| 1840 | + method, | ||
| 1841 | + } = prepareRequestHeadersObject({}, this)); | ||
| 1842 | + } else { | ||
| 1843 | + throw new ERR_INVALID_ARG_TYPE.HideStackFramesError( | ||
| 1844 | + 'headers', | ||
| 1845 | + ['Object', 'Array'], | ||
| 1846 | + headersParam, | ||
| 1847 | + ); | ||
| 1831 | 1848 | } | |
| 1832 | 1849 | ||
| 1833 | - assertIsObject(headers, 'headers'); | ||
| 1834 | 1850 | assertIsObject(options, 'options'); | |
| 1835 | - | ||
| 1836 | - headers = ObjectAssign({ __proto__: null }, headers); | ||
| 1837 | 1851 | options = { ...options }; | |
| 1838 | 1852 | ||
| 1839 | - if (headers[HTTP2_HEADER_METHOD] === undefined) | ||
| 1840 | - headers[HTTP2_HEADER_METHOD] = HTTP2_METHOD_GET; | ||
| 1841 | - | ||
| 1842 | - const connect = headers[HTTP2_HEADER_METHOD] === HTTP2_METHOD_CONNECT; | ||
| 1843 | - | ||
| 1844 | - if (!connect || headers[HTTP2_HEADER_PROTOCOL] !== undefined) { | ||
| 1845 | - if (getAuthority(headers) === undefined) | ||
| 1846 | - headers[HTTP2_HEADER_AUTHORITY] = this[kAuthority]; | ||
| 1847 | - if (headers[HTTP2_HEADER_SCHEME] === undefined) | ||
| 1848 | - headers[HTTP2_HEADER_SCHEME] = this[kProtocol].slice(0, -1); | ||
| 1849 | - if (headers[HTTP2_HEADER_PATH] === undefined) | ||
| 1850 | - headers[HTTP2_HEADER_PATH] = '/'; | ||
| 1851 | - } else { | ||
| 1852 | - if (headers[HTTP2_HEADER_AUTHORITY] === undefined) | ||
| 1853 | - throw new ERR_HTTP2_CONNECT_AUTHORITY(); | ||
| 1854 | - if (headers[HTTP2_HEADER_SCHEME] !== undefined) | ||
| 1855 | - throw new ERR_HTTP2_CONNECT_SCHEME(); | ||
| 1856 | - if (headers[HTTP2_HEADER_PATH] !== undefined) | ||
| 1857 | - throw new ERR_HTTP2_CONNECT_PATH(); | ||
| 1858 | - } | ||
| 1859 | - | ||
| 1860 | 1853 | setAndValidatePriorityOptions(options); | |
| 1861 | 1854 | ||
| 1862 | 1855 | if (options.endStream === undefined) { | |
| 1863 | 1856 | // For some methods, we know that a payload is meaningless, so end the | |
| 1864 | 1857 | // stream by default if the user has not specifically indicated a | |
| 1865 | 1858 | // preference. | |
| 1866 | - options.endStream = isPayloadMeaningless(headers[HTTP2_HEADER_METHOD]); | ||
| 1859 | + options.endStream = isPayloadMeaningless(method); | ||
| 1867 | 1860 | } else { | |
| 1868 | 1861 | validateBoolean(options.endStream, 'options.endStream'); | |
| 1869 | 1862 | } | |
| 1870 | 1863 | ||
| 1871 | - const headersList = mapToHeaders(headers); | ||
| 1872 | - | ||
| 1873 | 1864 | // eslint-disable-next-line no-use-before-define | |
| 1874 | 1865 | const stream = new ClientHttp2Stream(this, undefined, undefined, {}); | |
| 1875 | - stream[kSentHeaders] = headers; | ||
| 1876 | - stream[kOrigin] = `${headers[HTTP2_HEADER_SCHEME]}://` + | ||
| 1877 | - `${getAuthority(headers)}`; | ||
| 1866 | + stream[kSentHeaders] = headersObject; // N.b. Only set for object headers, not raw headers | ||
| 1867 | + stream[kOrigin] = `${scheme}://${authority}`; | ||
| 1878 | 1868 | const reqAsync = new AsyncResource('PendingRequest'); | |
| 1879 | 1869 | stream[kRequestAsyncResource] = reqAsync; | |
| 1880 | 1870 | ||
@@ -2350,7 +2340,7 @@ class Http2Stream extends Duplex { | |||
| 2350 | 2340 | ||
| 2351 | 2341 | this[kUpdateTimer](); | |
| 2352 | 2342 | ||
| 2353 | - const headersList = mapToHeaders(headers, assertValidPseudoHeaderTrailer); | ||
| 2343 | + const headersList = buildNgHeaderString(headers, assertValidPseudoHeaderTrailer); | ||
| 2354 | 2344 | this[kSentTrailers] = headers; | |
| 2355 | 2345 | ||
| 2356 | 2346 | // Send the trailers in setImmediate so we don't do it on nghttp2 stack. | |
@@ -2598,7 +2588,7 @@ function processRespondWithFD(self, fd, headers, offset = 0, length = -1, | |||
| 2598 | 2588 | ||
| 2599 | 2589 | let headersList; | |
| 2600 | 2590 | try { | |
| 2601 | - headersList = mapToHeaders(headers, assertValidPseudoHeaderResponse); | ||
| 2591 | + headersList = buildNgHeaderString(headers, assertValidPseudoHeaderResponse); | ||
| 2602 | 2592 | } catch (err) { | |
| 2603 | 2593 | self.destroy(err); | |
| 2604 | 2594 | return; | |
@@ -2822,7 +2812,7 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 2822 | 2812 | if (headers[HTTP2_HEADER_METHOD] === HTTP2_METHOD_HEAD) | |
| 2823 | 2813 | headRequest = options.endStream = true; | |
| 2824 | 2814 | ||
| 2825 | - const headersList = mapToHeaders(headers); | ||
| 2815 | + const headersList = buildNgHeaderString(headers); | ||
| 2826 | 2816 | ||
| 2827 | 2817 | const streamOptions = options.endStream ? STREAM_OPTION_EMPTY_PAYLOAD : 0; | |
| 2828 | 2818 | ||
@@ -2902,7 +2892,7 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 2902 | 2892 | } | |
| 2903 | 2893 | ||
| 2904 | 2894 | headers = processHeaders(headers, options); | |
| 2905 | - const headersList = mapToHeaders(headers, assertValidPseudoHeaderResponse); | ||
| 2895 | + const headersList = buildNgHeaderString(headers, assertValidPseudoHeaderResponse); | ||
| 2906 | 2896 | this[kSentHeaders] = headers; | |
| 2907 | 2897 | ||
| 2908 | 2898 | state.flags |= STREAM_FLAGS_HEADERS_SENT; | |
@@ -3079,7 +3069,7 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 3079 | 3069 | ||
| 3080 | 3070 | this[kUpdateTimer](); | |
| 3081 | 3071 | ||
| 3082 | - const headersList = mapToHeaders(headers, assertValidPseudoHeaderResponse); | ||
| 3072 | + const headersList = buildNgHeaderString(headers, assertValidPseudoHeaderResponse); | ||
| 3083 | 3073 | if (!this[kInfoHeaders]) | |
| 3084 | 3074 | this[kInfoHeaders] = [headers]; | |
| 3085 | 3075 | else | |
| Back | FazBrowse Home | New Git URL |
0 commit comments