/** * Represents responses returned by the Effect HTTP client. * * An `HttpClientResponse` keeps the original request together with the response * status, headers, cookies, and body accessors from the shared incoming-message * model. This module includes constructors, schema-based decoders, helpers for * streaming response bodies, and utilities for matching or filtering by HTTP * status. * * @stability unstable * @since 4.0.0 */ import * as Effect from "../Effect.ts"; import * as Option from "../Option.ts"; import { type Pipeable } from "../Pipeable.ts"; import * as Schema from "../Schema.ts"; import type { ParseOptions } from "../SchemaAST.ts"; import type * as Socket from "../socket/Socket.ts"; import * as Stream from "../Stream.ts"; import type { Unify } from "../Unify.ts"; import * as Cookies from "./Cookies.ts"; import * as Error from "./HttpClientError.ts"; import * as HttpClientRequest from "./HttpClientRequest.ts"; import * as HttpIncomingMessage from "./HttpIncomingMessage.ts"; /** * @stability unstable */ export { /** * Creates a decoder that reads a response JSON body and decodes it with the supplied schema. * * @stability unstable * @category schemas * @since 4.0.0 */ schemaBodyJson, /** * Creates a decoder that reads response URL-encoded body parameters and decodes them with the supplied schema. * * @stability unstable * @category schemas * @since 4.0.0 */ schemaBodyUrlParams, /** * Creates a decoder that validates and decodes response headers with the supplied schema. * * @stability unstable * @category schemas * @since 4.0.0 */ schemaHeaders } from "./HttpIncomingMessage.ts"; /** * Type identifier for `HttpClientResponse` values. * * @stability unstable * @category type IDs * @since 4.0.0 */ export declare const TypeId = "~effect/http/HttpClientResponse"; /** * Model of an HTTP client response, including the original request, status, cookies, headers, and body accessors. * * @stability unstable * @category models * @since 4.0.0 */ export interface HttpClientResponse extends HttpIncomingMessage.HttpIncomingMessage, Pipeable { readonly [TypeId]: typeof TypeId; readonly request: HttpClientRequest.HttpClientRequest; /** * The resolved URL, including query parameters and excluding the hash. * Uses the final URL when redirects are followed. Empty if unknown. */ readonly url: string; readonly status: number; readonly cookies: Cookies.Cookies; readonly formData: Effect.Effect; /** * Hands over the connection of a `101 Switching Protocols` response as a * `Socket`. * * **Details** * * Ask for an upgrade with `HttpClientRequest.upgrade`. Bytes the server * sent after the response head come first on the reader. Releasing the * writer's scope half-closes the connection, and releasing the reader's * scope closes it. Closing the request's scope (see `HttpClient.withScope`) * also closes it. * * Fails with a `StatusCodeError` for any other status, so a refusal can be * read from the response body as usual. Backends that cannot hand over a * connection, such as fetch, never produce a `101` and fail the same way. */ readonly upgrade: Effect.Effect; } /** * Wraps a Web `Response` and its original `HttpClientRequest` as an `HttpClientResponse`. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const fromWeb: (request: HttpClientRequest.HttpClientRequest, source: Response) => HttpClientResponse; /** * Returns the original Web `Response` of a fetch-backed `HttpClientResponse`. * * **When to use** * * Use to hand a response body to a Web API without copying it, such as * writing a fetched file to Cloudflare R2. The original body keeps runtime * capabilities, such as workerd's known length, that a stream converted from * `stream` does not. * * **Details** * * Returns `Some` for responses created with `fromWeb`, which includes every * response from `FetchHttpClient`, and `None` for other backends. * * Calling `toWeb` hands the body over: the response is no longer aborted when * the `HttpClientResponse` is garbage collected, so read or cancel the body * through the returned `Response`. * * **Gotchas** * * The body can be read once. After converting, read it from the returned * `Response`, not from the `HttpClientResponse`. * * After the hand-off, Effect aborts the request only when the scope of * `HttpClient.withScope` closes. When the request streams its body, finishing * or cancelling the returned body does not stop the upload; execute the * request with `HttpClient.withScope` and close the scope to stop it. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toWeb: (self: HttpClientResponse) => Option.Option; /** * Creates a decoder for a response's status, headers, and JSON body using the supplied schema. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaJson: > | undefined; readonly body?: unknown; }, RD>(schema: Schema.ConstraintCodec, options?: (ParseOptions & HttpIncomingMessage.JsonOptions) | undefined) => (self: HttpClientResponse) => Effect.Effect; /** * Creates a decoder for a response's status and headers without reading a response body. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaNoBody: > | undefined; }, RD, RE>(schema: Schema.Codec, options?: ParseOptions | undefined) => (self: HttpClientResponse) => Effect.Effect; /** * Converts an effect producing an `HttpClientResponse` into a stream of response body bytes. * * @stability unstable * @category accessors * @since 4.0.0 */ export declare const stream: (effect: Effect.Effect) => Stream.Stream; /** * Pattern matches on a response status, checking exact status handlers before status-class handlers and `orElse`. * * @stability unstable * @category pattern matching * @since 4.0.0 */ export declare const matchStatus: { /** * Pattern matches on a response status, checking exact status handlers before status-class handlers and `orElse`. * * @stability unstable * @category pattern matching * @since 4.0.0 */ any; readonly "2xx"?: (_: HttpClientResponse) => any; readonly "3xx"?: (_: HttpClientResponse) => any; readonly "4xx"?: (_: HttpClientResponse) => any; readonly "5xx"?: (_: HttpClientResponse) => any; readonly orElse: (_: HttpClientResponse) => any; }>(cases: Cases): (self: HttpClientResponse) => Cases[keyof Cases] extends (_: any) => infer R ? Unify : never; /** * Pattern matches on a response status, checking exact status handlers before status-class handlers and `orElse`. * * @stability unstable * @category pattern matching * @since 4.0.0 */ any; readonly "2xx"?: (_: HttpClientResponse) => any; readonly "3xx"?: (_: HttpClientResponse) => any; readonly "4xx"?: (_: HttpClientResponse) => any; readonly "5xx"?: (_: HttpClientResponse) => any; readonly orElse: (_: HttpClientResponse) => any; }>(self: HttpClientResponse, cases: Cases): Cases[keyof Cases] extends (_: any) => infer R ? Unify : never; }; /** * Succeeds with the response when its status satisfies the predicate, otherwise fails with `HttpClientError`. * * @stability unstable * @category filtering * @since 4.0.0 */ export declare const filterStatus: { /** * Succeeds with the response when its status satisfies the predicate, otherwise fails with `HttpClientError`. * * @stability unstable * @category filtering * @since 4.0.0 */ (f: (status: number) => boolean): (self: HttpClientResponse) => Effect.Effect; /** * Succeeds with the response when its status satisfies the predicate, otherwise fails with `HttpClientError`. * * @stability unstable * @category filtering * @since 4.0.0 */ (self: HttpClientResponse, f: (status: number) => boolean): Effect.Effect; }; /** * Succeeds with the response only when its status is in the 2xx range, otherwise fails with `HttpClientError`. * * @stability unstable * @category filtering * @since 4.0.0 */ export declare const filterStatusOk: (self: HttpClientResponse) => Effect.Effect; //# sourceMappingURL=HttpClientResponse.d.ts.map