MCPcopy Create free account
hub / github.com/Effect-TS/effect / writeHead

Function writeHead

packages/platform/node/src/NodeHttpServer.ts:1116–1135  ·  view source on GitHub ↗
(
  nodeResponse: Http.ServerResponse,
  response: HttpServerResponse,
  headers: Record<string, string | Array<string>>,
  streaming = false
)

Source from the content-addressed store, hash-verified

1114const invalidStatusError = (status: number) => new RangeError(`Invalid final response status: ${status}`)
1115
1116const 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.

Callers 2

writeResponseFunction · 0.85
handleCauseFunction · 0.85

Calls 5

isFinalStatusFunction · 0.85
invalidStatusErrorFunction · 0.85
isHttp2Function · 0.85
withoutConnectionHeadersFunction · 0.85
closesConnectionFunction · 0.85

Tested by

no test coverage detected