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

Class WebHttpClientResponse

packages/effect/src/http/HttpClientResponse.ts:413–582  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411// -----------------------------------------------------------------------------
412
413class WebHttpClientResponse extends Inspectable.Class implements HttpClientResponse, Pipeable {
414 readonly [HttpIncomingMessage.TypeId]: typeof HttpIncomingMessage.TypeId
415 readonly [TypeId]: typeof TypeId
416
417 readonly request: HttpClientRequest.HttpClientRequest
418 private readonly source: globalThis.Response
419
420 constructor(
421 request: HttpClientRequest.HttpClientRequest,
422 source: globalThis.Response
423 ) {
424 super()
425 this.request = request
426 this.source = source
427 this[HttpIncomingMessage.TypeId] = HttpIncomingMessage.TypeId
428 this[TypeId] = TypeId
429 }
430
431 toJSON(): unknown {
432 return HttpIncomingMessage.inspect(this, {
433 _id: "HttpClientResponse",
434 request: this.request.toJSON(),
435 status: this.status
436 })
437 }
438
439 get status(): number {
440 return this.source.status
441 }
442
443 get url(): string {
444 if (this.source.url) return this.source.url.split("#")[0]
445 const url = HttpClientRequest.toUrl(this.request)
446 if (Option.isNone(url)) return ""
447 url.value.hash = ""
448 return url.value.href
449 }
450
451 cachedHeaders?: Headers.Headers
452 get headers(): Headers.Headers {
453 return this.cachedHeaders ??= Headers.fromInput(this.source.headers)
454 }
455
456 cachedCookies?: Cookies.Cookies
457 get cookies(): Cookies.Cookies {
458 if (this.cachedCookies) {
459 return this.cachedCookies
460 }
461 // React Native's Headers does not implement getSetCookie, and it never
462 // exposes Set-Cookie to JavaScript anyway.
463 return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie?.() ?? [])
464 }
465
466 get remoteAddress(): Option.Option<string> {
467 return Option.none()
468 }
469
470 [WebSourceSymbol](): globalThis.Response {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected