import type { ServerResponse } from "node:http"; import { Body, type BodyLike } from "./body.js"; import { type ExtensionKey, Extensions } from "./extensions.js"; import { type HeaderEntryLike, HeaderMap } from "./headers.js"; import { StatusCode } from "./status.js"; import { type ToHttpResponse } from "./to-response.js"; import { type ToHttpResponseParts } from "./to-response-parts.js"; /** * Represents an HTTP response. * * See {@link http | Ownership and Reuse Contract} in the module documentation. */ export declare class HttpResponse { status: StatusCode; headers: HeaderMap; body: Body; extensions: Extensions; /** * Creates a new {@link HttpResponse}. */ constructor(status: StatusCode, headers: HeaderMap, body: Body, extensions?: Extensions); /** * Creates a new {@link HttpResponse} from a {@link HttpResponseLike} value. */ static from(response: HttpResponseLike): HttpResponse; private static extendFromParts; /** * Creates a new {@link HttpResponseBuilder}. */ static builder(): HttpResponseBuilder; /** * Writes the response data, including headers and body, to the provided * {@link ServerResponse}. */ write(res: ServerResponse): Promise; toJSON(): Record; } /** * Builder for creating HTTP responses. */ export declare class HttpResponseBuilder { private status_; private headers_; private extensions_; status(status: StatusCode | number): this; headers(headers: HeaderMap): this; header(key: string, value: string): this; extensions(extensions: Extensions): this; extension(key: ExtensionKey, value: T): this; body(body: BodyLike): HttpResponse; } /** * Represents a type that can be used as a response in HTTP operations. * * This type can be one of the following: * * - {@link HttpResponse}: Represents a standard HTTP response with headers, * status, and body. * - {@link ToHttpResponse}: Represents an object or function that can be * transformed into an `HttpResponse`. * - {@link BodyLike}: Represents a type that can be interpreted or converted to * the body of an HTTP response. * * It is used to provide flexibility in handling various forms of HTTP response * data. */ export type HttpResponseLikePart = HttpResponse | ToHttpResponse | BodyLike | Response; /** * Represents a type that can be used as a response part. */ export type ToHttpResponsePartsLike = ToHttpResponseParts | Iterable; /** * Represents a value that can be converted into a full {@link HttpResponse}. * * This type allows for flexible construction of HTTP responses from various * forms of input. Possible structures include: * * 1. A single {@link HttpResponseLikePart}: * - Directly represents a complete response, a response-convertible object, * or a body-like value. * * 2. An array where the last element is a {@link HttpResponseLikePart} and * preceding elements are {@link ToHttpResponsePartsLike}: * - The last element is converted first into a base response. * - Leading elements are applied from left to right, overriding values * from the previous elements. * * 3. A tuple starting with a status code ({@link StatusCode} or `number`) or * an {@link HttpResponse}, followed by zero or more * {@link ToHttpResponsePartsLike}, and ending with a * {@link HttpResponseLikePart}: * - The last element is converted first into a base response. * - Middle {@link ToHttpResponsePartsLike} elements are merged in order, * overriding the base response. * - The first element (status code, number, or {@link HttpResponse}) is * applied last, overriding any previous status, headers, or extensions. * * ## Merging behavior * * Except for the leading element in tuple forms, later elements override the * values of earlier elements. For example, headers and status from later * parts replace those from earlier ones. */ export type HttpResponseLike = HttpResponseLikePart | [...ToHttpResponsePartsLike[], HttpResponseLikePart] | [StatusCode | number | HttpResponse, ...ToHttpResponsePartsLike[], HttpResponseLikePart];