( nodeResponse: Http.ServerResponse, response: HttpServerResponse, headers: Record<string, string | Array<string>>, streaming = false )
| 1114 | const invalidStatusError = (status: number) => new RangeError(`Invalid final response status: ${status}`) |
| 1115 | |
| 1116 | const writeHead = ( |
| 1117 | nodeResponse: Http.ServerResponse, |
| 1118 | response: HttpServerResponse, |
| 1119 | headers: Record<string, string | Array<string>>, |
| 1120 | streaming = false |
| 1121 | ): void => { |
| 1122 | if (!isFinalStatus(response.status)) { |
| 1123 | throw invalidStatusError(response.status) |
| 1124 | } |
| 1125 | if (isHttp2(nodeResponse.req)) { |
| 1126 | // HTTP/2 has no status message |
| 1127 | nodeResponse.writeHead(response.status, withoutConnectionHeaders(headers)) |
| 1128 | return |
| 1129 | } |
| 1130 | nodeResponse.writeHead( |
| 1131 | response.status, |
| 1132 | response.statusText, |
| 1133 | closesConnection(nodeResponse.req, streaming) ? { ...headers, connection: "close" } : headers |
| 1134 | ) |
| 1135 | } |
| 1136 | |
| 1137 | // RFC 9113 §8.2.2: HTTP/2 forbids connection-specific headers, and Node rejects them. They |
| 1138 | // mostly come from proxied HTTP/1.1 responses, so they are dropped rather than failing the response. |
no test coverage detected