/** * Provides server-side access to the current incoming HTTP request. * * `HttpServerRequest` is the context service used by handlers, middleware, * schema decoders, multipart parsers, WebSocket upgrades, and adapters. A * request stores its method, URL, original URL, headers, cookies, remote * address, body stream, and platform source object. This module also includes * request conversions and schema decoders for cookies, headers, search * parameters, JSON, forms, URL-encoded bodies, and multipart bodies. * * @stability unstable * @since 4.0.0 */ import type * as Arr from "../Array.ts"; import * as Channel from "../Channel.ts"; import * as Context from "../Context.ts"; import * as Effect from "../Effect.ts"; import type * as FileSystem from "../FileSystem.ts"; import * as Option from "../Option.ts"; import type * as Path from "../Path.ts"; import type { ReadonlyRecord } from "../Record.ts"; import * as Result from "../Result.ts"; import * as Schema from "../Schema.ts"; import type { ParseOptions } from "../SchemaAST.ts"; import type * as Scope from "../Scope.ts"; import * as Socket from "../socket/Socket.ts"; import * as Stream from "../Stream.ts"; import * as Headers from "./Headers.ts"; import * as HttpClientRequest from "./HttpClientRequest.ts"; import * as HttpIncomingMessage from "./HttpIncomingMessage.ts"; import { type HttpMethod } from "./HttpMethod.ts"; import { HttpServerError, type RequestError } from "./HttpServerError.ts"; import * as Multipart from "./Multipart.ts"; /** * @stability unstable */ export { /** * Provides the `MaxBodySize` fiber reference for configuring request body limits. * * **When to use** * * Use to configure the maximum body size accepted while reading server * request bodies. * * @stability unstable * @category references * @since 4.0.0 */ MaxBodySize } from "./HttpIncomingMessage.ts"; /** * Runtime type identifier for `HttpServerRequest` values. * * @stability unstable * @category type IDs * @since 4.0.0 */ export declare const TypeId = "~effect/http/HttpServerRequest"; /** * Server-side representation of an incoming HTTP request. * * **Details** * * It extends `HttpIncomingMessage` with request metadata, parsed cookies, * multipart accessors, connection upgrades, and a `modify` method for * creating adjusted request views. `upgrade` completes a WebSocket handshake * for `Upgrade: websocket`. Platforms that can hand over the connection, such * as Node, answer other protocols with `101 Switching Protocols` and expose * the raw connection. * * @stability unstable * @category models * @since 4.0.0 */ export interface HttpServerRequest extends HttpIncomingMessage.HttpIncomingMessage { readonly [TypeId]: typeof TypeId; readonly source: object; readonly url: string; readonly originalUrl: string; readonly method: HttpMethod; readonly cookies: ReadonlyRecord; readonly multipart: Effect.Effect; readonly multipartStream: Stream.Stream; readonly upgrade: Effect.Effect; /** * Address of the directly connected peer. Trusted proxy middleware replaces * `remoteAddress` with the forwarded client address and keeps the previous * value here; otherwise it equals `remoteAddress`. */ readonly peerAddress: Option.Option; /** * Scheme validated by trusted proxy middleware. `toURL` prefers it over the * scheme of the transport connection. */ readonly protocol: "http" | "https" | undefined; readonly modify: (options: { readonly url?: string; readonly headers?: Headers.Headers; readonly remoteAddress?: Option.Option; readonly peerAddress?: Option.Option; readonly protocol?: "http" | "https"; }) => HttpServerRequest; } /** * Service tag for the active server-side HTTP request. * * **When to use** * * Use to access the request currently being handled by HTTP server routes and * middleware. * * @stability unstable * @category services * @since 4.0.0 */ export declare const HttpServerRequest: Context.Service; declare const ParsedSearchParams_base: Context.ServiceClass>; /** * Service that contains decoded URL query parameters for the current request. * * **When to use** * * Use to access query parameters that have already been parsed for the current * server request. * * **Details** * * Each key maps to a string value, or to an array when the parameter appears more * than once. * * @stability unstable * @category services * @since 4.0.0 */ export declare class ParsedSearchParams extends ParsedSearchParams_base { } /** * Converts a `URL` object's search parameters into a record. * * **Details** * * Repeated parameters are represented as arrays in insertion order. * * @stability unstable * @category parsing * @since 4.0.0 */ export declare const searchParamsFromURL: (url: URL) => ReadonlyRecord>; /** * Creates a channel backed by the current request's upgraded socket. * * **Details** * * The channel reads incoming socket messages and writes byte chunks to the * socket, failing if the request cannot be upgraded or the socket fails. * * @stability unstable * @category accessors * @since 4.0.0 */ export declare const upgradeChannel: () => Channel.Channel, HttpServerError | IE | Socket.SocketError, void, Arr.NonEmptyReadonlyArray, IE, unknown, HttpServerRequest>; /** * Decodes a schema from the cookies of the current request. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaCookies: >, RD>(schema: Schema.ConstraintCodec, options?: ParseOptions | undefined) => Effect.Effect; /** * Decodes a schema from the headers of the current request. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaHeaders: >, RD>(schema: Schema.ConstraintCodec, options?: ParseOptions | undefined) => Effect.Effect; /** * Decodes a schema from the parsed search parameters of the current request. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaSearchParams: | undefined>>, RD>(schema: Schema.ConstraintCodec, options?: ParseOptions | undefined) => Effect.Effect; /** * Reads the current request body as JSON and decodes it with the supplied schema. * * **Details** * * The effect can fail if the body cannot be read or parsed, or if schema decoding * fails. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaBodyJson: (schema: Schema.ConstraintDecoder, options?: (ParseOptions & HttpIncomingMessage.JsonOptions) | undefined) => Effect.Effect; /** * Decodes the current request body as form data. * * **Details** * * Multipart requests are persisted and decoded as multipart data; other form * requests are decoded from URL-encoded body parameters. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaBodyForm: , RD>(schema: Schema.ConstraintCodec, options?: ParseOptions | undefined) => Effect.Effect; /** * Reads the current request body as URL-encoded parameters and decodes them with * the supplied schema. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaBodyUrlParams: | undefined>>, RD>(schema: Schema.ConstraintCodec, options?: ParseOptions | undefined) => Effect.Effect; /** * Persists the current multipart request body and decodes it with the supplied * schema. * * **Details** * * The effect requires the services needed to persist multipart files, including a * scope, file system, and path service. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaBodyMultipart: , RD>(schema: Schema.ConstraintCodec, options?: ParseOptions | undefined) => Effect.Effect; /** * Creates a decoder for a JSON value stored in a form field. * * **Details** * * For multipart requests, the named multipart field is decoded as JSON. For * URL-encoded requests, the named parameter is decoded as JSON and then decoded * with the supplied schema. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const schemaBodyFormJson: (schema: Schema.ConstraintDecoder, options?: (ParseOptions & HttpIncomingMessage.JsonOptions) | undefined) => (field: string) => Effect.Effect; /** * Creates an `HttpServerRequest` view of an `HttpClientRequest`. * * **Details** * * If the client request can be converted to an absolute URL, that URL is used as * the original URL. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const fromClientRequest: (request: HttpClientRequest.HttpClientRequest) => HttpServerRequest; /** * Wraps a Web `Request` as an `HttpServerRequest`. * * **Details** * * The request's current URL is stored without the scheme and host, while the * original Web URL remains available as `originalUrl`. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const fromWeb: (request: globalThis.Request) => HttpServerRequest; /** * Converts an `HttpServerRequest` into an `HttpClientRequest`. * * **Details** * * The converted request preserves the method, headers, body stream, and a URL * derived from the request when possible. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toClientRequest: (request: HttpServerRequest) => HttpClientRequest.HttpClientRequest; /** * Attempts to construct an absolute `URL` for a server request safely. * * **Details** * * Uses `host` (defaulting to `localhost`) and the request `protocol` set by * trusted proxy middleware. Otherwise, infers HTTPS from a case-insensitive * `https:` prefix in `originalUrl`, defaulting to HTTP. Forwarding headers such * as `x-forwarded-proto` are never read directly; use * `HttpMiddleware.xForwardedHeaders` behind a TLS-terminating proxy. An * absolute `url` keeps its own protocol and host. Invalid URLs return * `Option.none`. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toURL: (self: HttpServerRequest) => Option.Option; /** * Converts an `HttpServerRequest` safely to a Web `Request` as a `Result`. * * **Details** * * If the source is already a Web `Request`, it is returned unchanged. Otherwise * an absolute URL is derived from the request; invalid URLs fail with a * `RequestParseError`. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toWebResult: (self: HttpServerRequest, options?: { readonly signal?: AbortSignal | undefined; readonly context?: Context.Context | undefined; }) => Result.Result; /** * Converts an `HttpServerRequest` to a Web `Request` in `Effect`. * * **Details** * * The current context is used when streaming the request body into the Web * request. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toWeb: (self: HttpServerRequest, options?: { readonly signal?: AbortSignal | undefined; }) => Effect.Effect; //# sourceMappingURL=HttpServerRequest.d.ts.map