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

Function makeResponse

packages/effect/src/http/HttpServerResponse.ts:1479–1515  ·  view source on GitHub ↗
(options: {
  readonly status: number
  readonly statusText?: string | undefined
  readonly headers?: Headers.Headers | undefined
  readonly cookies?: Cookies.Cookies | undefined
  readonly body?: Body.HttpBody | undefined
}, ownedHeaders?: Headers.Headers)

Source from the content-addressed store, hash-verified

1477}
1478
1479const makeResponse = (options: {
1480 readonly status: number
1481 readonly statusText?: string | undefined
1482 readonly headers?: Headers.Headers | undefined
1483 readonly cookies?: Cookies.Cookies | undefined
1484 readonly body?: Body.HttpBody | undefined
1485}, ownedHeaders?: Headers.Headers) => {
1486 // ownedHeaders is a freshly created map that nothing else references, so it
1487 // can be completed in place instead of copied. It supersedes options.headers,
1488 // and explicit content headers in it take precedence over body-derived ones.
1489 const self = Object.create(Proto) as Mutable<HttpServerResponse>
1490 self.status = options.status
1491 self.statusText = options.statusText
1492 self.cookies = options.cookies ?? Cookies.empty
1493 self.body = options.body ?? Body.empty
1494 if (
1495 self.body._tag !== "Empty" &&
1496 (self.body.contentType || self.body.contentLength !== undefined)
1497 ) {
1498 const owned = ownedHeaders !== undefined
1499 const newHeaders = owned
1500 ? ownedHeaders as any
1501 : options.headers === undefined || options.headers === Headers.empty
1502 ? headersInternal.emptyMutableUnsafe() as any
1503 : Headers.fromRecordUnsafe({ ...options.headers }) as any
1504 if (self.body.contentType && (!owned || newHeaders["content-type"] === undefined)) {
1505 newHeaders["content-type"] = self.body.contentType
1506 }
1507 if (self.body.contentLength !== undefined && (!owned || newHeaders["content-length"] === undefined)) {
1508 newHeaders["content-length"] = self.body.contentLength.toString()
1509 }
1510 self.headers = newHeaders
1511 } else {
1512 self.headers = ownedHeaders ?? options.headers ?? Headers.empty
1513 }
1514 return self
1515}
1516
1517// Shares the headers of `self`, so explicit content headers are not replaced
1518// with the body's.

Callers 15

emptyFunction · 0.70
redirectFunction · 0.70
uint8ArrayFunction · 0.70
textFunction · 0.70
jsonFunction · 0.70
schemaJsonFunction · 0.70
jsonUnsafeFunction · 0.70
urlParamsFunction · 0.70
rawFunction · 0.70
formDataFunction · 0.70
streamFunction · 0.70

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected