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

Class NodeHttpResponse

packages/platform/node/src/NodeHttpClient.ts:580–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

578 })
579
580class NodeHttpResponse extends NodeHttpIncomingMessage<Error.HttpClientError> implements HttpClientResponse, Pipeable {
581 readonly [Response.TypeId]: typeof Response.TypeId
582 readonly request: HttpClientRequest
583
584 constructor(
585 request: HttpClientRequest,
586 source: Http.IncomingMessage
587 ) {
588 super(source, (cause) =>
589 new Error.HttpClientError({
590 reason: new Error.DecodeError({
591 request,
592 response: this,
593 cause
594 })
595 }))
596 this[Response.TypeId] = Response.TypeId
597 this.request = request
598 }
599
600 get status() {
601 return this.source.statusCode!
602 }
603
604 cachedCookies?: Cookies.Cookies
605 get cookies(): Cookies.Cookies {
606 if (this.cachedCookies !== undefined) {
607 return this.cachedCookies
608 }
609 const header = this.source.headers["set-cookie"]
610 return this.cachedCookies = header ? Cookies.fromSetCookie(header) : Cookies.empty
611 }
612
613 get formData(): Effect.Effect<FormData, Error.HttpClientError> {
614 return Effect.tryPromise({
615 try: () => {
616 const init: {
617 headers: HeadersInit
618 status?: number
619 statusText?: string
620 } = {
621 headers: new globalThis.Headers(this.source.headers as any)
622 }
623
624 if (this.source.statusCode) {
625 init.status = this.source.statusCode
626 }
627
628 if (this.source.statusMessage) {
629 init.statusText = this.source.statusMessage
630 }
631
632 return new globalThis.Response(Readable.toWeb(this.source) as any, init).formData()
633 },
634 catch: this.onError
635 })
636 }
637

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected