| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f11ac0d commit af3a17e
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2654,31 +2654,35 @@ function prepareResponseHeaders(stream, headersParam, options) { | |||
| 2654 | 2654 | function prepareResponseHeadersObject(oldHeaders, options) { | |
| 2655 | 2655 | assertIsObject(oldHeaders, 'headers', ['Object', 'Array']); | |
| 2656 | 2656 | const headers = { __proto__: null }; | |
| 2657 | + let statusCode; | ||
| 2658 | + let hasDate = false; | ||
| 2657 | 2659 | ||
| 2658 | 2660 | if (oldHeaders !== null && oldHeaders !== undefined) { | |
| 2659 | 2661 | // This loop is here for performance reason. Do not change. | |
| 2662 | + // The :status and date fields are picked up while copying so they do | ||
| 2663 | + // not have to be looked up again on the null-prototype copy. | ||
| 2660 | 2664 | for (const key in oldHeaders) { | |
| 2661 | 2665 | if (ObjectHasOwn(oldHeaders, key)) { | |
| 2662 | - headers[key] = oldHeaders[key]; | ||
| 2666 | + const value = oldHeaders[key]; | ||
| 2667 | + headers[key] = value; | ||
| 2668 | + if (key === HTTP2_HEADER_STATUS) | ||
| 2669 | + statusCode = value; | ||
| 2670 | + else if (key === HTTP2_HEADER_DATE) | ||
| 2671 | + hasDate = value != null; | ||
| 2663 | 2672 | } | |
| 2664 | 2673 | } | |
| 2665 | 2674 | headers[kSensitiveHeaders] = oldHeaders[kSensitiveHeaders]; | |
| 2666 | 2675 | } | |
| 2667 | 2676 | ||
| 2668 | - const statusCode = | ||
| 2669 | - headers[HTTP2_HEADER_STATUS] = | ||
| 2670 | - headers[HTTP2_HEADER_STATUS] | 0 || HTTP_STATUS_OK; | ||
| 2677 | + statusCode = headers[HTTP2_HEADER_STATUS] = statusCode | 0 || HTTP_STATUS_OK; | ||
| 2671 | 2678 | ||
| 2672 | - if (options.sendDate == null || options.sendDate) { | ||
| 2673 | - headers[HTTP2_HEADER_DATE] ??= utcDate(); | ||
| 2679 | + if (!hasDate && (options.sendDate == null || options.sendDate)) { | ||
| 2680 | + headers[HTTP2_HEADER_DATE] = utcDate(); | ||
| 2674 | 2681 | } | |
| 2675 | 2682 | ||
| 2676 | 2683 | validatePreparedResponseHeaders(headers, statusCode); | |
| 2677 | 2684 | ||
| 2678 | - return { | ||
| 2679 | - headers, | ||
| 2680 | - statusCode: headers[HTTP2_HEADER_STATUS], | ||
| 2681 | - }; | ||
| 2685 | + return { headers, statusCode }; | ||
| 2682 | 2686 | } | |
| 2683 | 2687 | ||
| 2684 | 2688 | function prepareResponseHeadersArray(headers, options) { | |
@@ -3047,15 +3051,17 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 3047 | 3051 | const state = this[kState]; | |
| 3048 | 3052 | ||
| 3049 | 3053 | assertIsObject(options, 'options'); | |
| 3050 | - options = { ...options }; | ||
| 3054 | + // The options are only read, never mutated, so the user-provided object | ||
| 3055 | + // can be used directly instead of copying it. | ||
| 3056 | + options ??= kEmptyObject; | ||
| 3051 | 3057 | ||
| 3052 | 3058 | debugStreamObj(this, 'initiating response'); | |
| 3053 | 3059 | this[kUpdateTimer](); | |
| 3054 | 3060 | ||
| 3055 | - options.endStream = !!options.endStream; | ||
| 3061 | + const endStream = !!options.endStream; | ||
| 3056 | 3062 | ||
| 3057 | 3063 | let streamOptions = 0; | |
| 3058 | - if (options.endStream) | ||
| 3064 | + if (endStream) | ||
| 3059 | 3065 | streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD; | |
| 3060 | 3066 | ||
| 3061 | 3067 | if (options.waitForTrailers) { | |
@@ -3073,12 +3079,11 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 3073 | 3079 | ||
| 3074 | 3080 | // Close the writable side if the endStream option is set or status | |
| 3075 | 3081 | // is one of known codes with no payload, or it's a head request | |
| 3076 | - if (!!options.endStream || | ||
| 3082 | + if (endStream || | ||
| 3077 | 3083 | statusCode === HTTP_STATUS_NO_CONTENT || | |
| 3078 | 3084 | statusCode === HTTP_STATUS_RESET_CONTENT || | |
| 3079 | 3085 | statusCode === HTTP_STATUS_NOT_MODIFIED || | |
| 3080 | 3086 | this.headRequest === true) { | |
| 3081 | - options.endStream = true; | ||
| 3082 | 3087 | this.end(); | |
| 3083 | 3088 | } | |
| 3084 | 3089 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments