| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fa1a5f3 commit b5d5dd7
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2654,35 +2654,31 @@ 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; | ||
| 2659 | 2657 | ||
| 2660 | 2658 | if (oldHeaders !== null && oldHeaders !== undefined) { | |
| 2661 | 2659 | // 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. | ||
| 2664 | 2660 | for (const key in oldHeaders) { | |
| 2665 | 2661 | if (ObjectHasOwn(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; | ||
| 2662 | + headers[key] = oldHeaders[key]; | ||
| 2672 | 2663 | } | |
| 2673 | 2664 | } | |
| 2674 | 2665 | headers[kSensitiveHeaders] = oldHeaders[kSensitiveHeaders]; | |
| 2675 | 2666 | } | |
| 2676 | 2667 | ||
| 2677 | - statusCode = headers[HTTP2_HEADER_STATUS] = statusCode | 0 || HTTP_STATUS_OK; | ||
| 2668 | + const statusCode = | ||
| 2669 | + headers[HTTP2_HEADER_STATUS] = | ||
| 2670 | + headers[HTTP2_HEADER_STATUS] | 0 || HTTP_STATUS_OK; | ||
| 2678 | 2671 | ||
| 2679 | - if (!hasDate && (options.sendDate == null || options.sendDate)) { | ||
| 2680 | - headers[HTTP2_HEADER_DATE] = utcDate(); | ||
| 2672 | + if (options.sendDate == null || options.sendDate) { | ||
| 2673 | + headers[HTTP2_HEADER_DATE] ??= utcDate(); | ||
| 2681 | 2674 | } | |
| 2682 | 2675 | ||
| 2683 | 2676 | validatePreparedResponseHeaders(headers, statusCode); | |
| 2684 | 2677 | ||
| 2685 | - return { headers, statusCode }; | ||
| 2678 | + return { | ||
| 2679 | + headers, | ||
| 2680 | + statusCode: headers[HTTP2_HEADER_STATUS], | ||
| 2681 | + }; | ||
| 2686 | 2682 | } | |
| 2687 | 2683 | ||
| 2688 | 2684 | function prepareResponseHeadersArray(headers, options) { | |
@@ -3051,17 +3047,15 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 3051 | 3047 | const state = this[kState]; | |
| 3052 | 3048 | ||
| 3053 | 3049 | assertIsObject(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; | ||
| 3050 | + options = { ...options }; | ||
| 3057 | 3051 | ||
| 3058 | 3052 | debugStreamObj(this, 'initiating response'); | |
| 3059 | 3053 | this[kUpdateTimer](); | |
| 3060 | 3054 | ||
| 3061 | - const endStream = !!options.endStream; | ||
| 3055 | + options.endStream = !!options.endStream; | ||
| 3062 | 3056 | ||
| 3063 | 3057 | let streamOptions = 0; | |
| 3064 | - if (endStream) | ||
| 3058 | + if (options.endStream) | ||
| 3065 | 3059 | streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD; | |
| 3066 | 3060 | ||
| 3067 | 3061 | if (options.waitForTrailers) { | |
@@ -3079,11 +3073,12 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 3079 | 3073 | ||
| 3080 | 3074 | // Close the writable side if the endStream option is set or status | |
| 3081 | 3075 | // is one of known codes with no payload, or it's a head request | |
| 3082 | - if (endStream || | ||
| 3076 | + if (!!options.endStream || | ||
| 3083 | 3077 | statusCode === HTTP_STATUS_NO_CONTENT || | |
| 3084 | 3078 | statusCode === HTTP_STATUS_RESET_CONTENT || | |
| 3085 | 3079 | statusCode === HTTP_STATUS_NOT_MODIFIED || | |
| 3086 | 3080 | this.headRequest === true) { | |
| 3081 | + options.endStream = true; | ||
| 3087 | 3082 | this.end(); | |
| 3088 | 3083 | } | |
| 3089 | 3084 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments