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

Function makeResponse

packages/effect/src/unstable/http/HttpServerResponse.ts:1336–1364  ·  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
}, preferHeaders = false)

Source from the content-addressed store, hash-verified

1334}
1335
1336const makeResponse = (options: {
1337 readonly status: number
1338 readonly statusText?: string | undefined
1339 readonly headers?: Headers.Headers | undefined
1340 readonly cookies?: Cookies.Cookies | undefined
1341 readonly body?: Body.HttpBody | undefined
1342}, preferHeaders = false) => {
1343 const self = Object.create(Proto) as Mutable<HttpServerResponse>
1344 self.status = options.status
1345 self.statusText = options.statusText
1346 self.cookies = options.cookies ?? Cookies.empty
1347 self.body = options.body ?? Body.empty
1348 if (
1349 self.body._tag !== "Empty" &&
1350 (self.body.contentType || self.body.contentLength !== undefined)
1351 ) {
1352 const newHeaders = Headers.fromRecordUnsafe({ ...options.headers }) as any
1353 if (self.body.contentType && (!preferHeaders || newHeaders["content-type"] === undefined)) {
1354 newHeaders["content-type"] = self.body.contentType
1355 }
1356 if (self.body.contentLength !== undefined && (!preferHeaders || newHeaders["content-length"] === undefined)) {
1357 newHeaders["content-length"] = self.body.contentLength.toString()
1358 }
1359 self.headers = newHeaders
1360 } else {
1361 self.headers = options.headers ?? Headers.empty
1362 }
1363 return self
1364}
1365
1366/**
1367 * Converts a Web `Response` to an `HttpServerResponse`.

Callers 13

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