import * as Context from "../Context.ts"; import * as Effect from "../Effect.ts"; import * as Layer from "../Layer.ts"; import * as Scope from "../Scope.ts"; import { type HttpMiddleware } from "./HttpMiddleware.ts"; import { HttpServerError } from "./HttpServerError.ts"; import { HttpServerRequest } from "./HttpServerRequest.ts"; import type { HttpServerResponse } from "./HttpServerResponse.ts"; /** * Runs an HTTP server effect, sends the produced response with the supplied handler, and converts failures into HTTP responses. * On handler failure, the request scope closes with the original cause. * If the send handler returns an `HttpServerResponse`, such as the `101` * response of an upgraded request, middleware observes it in place of the * handler's response. * * @stability unstable * @category combinators * @since 4.0.0 */ export declare const toHandled: (self: Effect.Effect, handleResponse: (request: HttpServerRequest, response: HttpServerResponse) => Effect.Effect, middleware?: HttpMiddleware | undefined) => Effect.Effect>; /** * Disables automatic closing for an HTTP request scope. * * **Gotchas** * * Use only when another owner will close the scope; otherwise resources attached * to the request scope can leak. * * @stability unstable * @category resource management * @since 4.0.0 */ export declare const scopeDisableClose: (scope: Scope.Scope) => void; /** * Returns a streaming server response that closes the request scope when the body stream exits. * * @stability unstable * @category resource management * @since 4.0.0 */ export declare const scopeTransferToStream: (response: HttpServerResponse) => HttpServerResponse; /** * Function run with the current request and response just before the response is sent, allowing the response to be replaced or failing with `HttpServerError`. * * @stability unstable * @category handlers * @since 4.0.0 */ export type PreResponseHandler = (request: HttpServerRequest, response: HttpServerResponse) => Effect.Effect; /** * Registers an additional pre-response handler for the current HTTP server request. * * @stability unstable * @category handlers * @since 4.0.0 */ export declare const appendPreResponseHandler: (handler: PreResponseHandler) => Effect.Effect; /** * Registers a pre-response handler for the HTTP server request that owns the * supplied fiber context. Does nothing outside a server request. * * @stability unstable * @category unsafe * @since 4.0.0 */ export declare const appendPreResponseHandlerUnsafe: (context: Context.Context, handler: PreResponseHandler) => void; /** * Runs an effect after registering a pre-response handler for the current HTTP server request. * * @stability unstable * @category handlers * @since 4.0.0 */ export declare const withPreResponseHandler: { /** * Runs an effect after registering a pre-response handler for the current HTTP server request. * * @stability unstable * @category handlers * @since 4.0.0 */ (handler: PreResponseHandler): (self: Effect.Effect) => Effect.Effect; /** * Runs an effect after registering a pre-response handler for the current HTTP server request. * * @stability unstable * @category handlers * @since 4.0.0 */ (self: Effect.Effect, handler: PreResponseHandler): Effect.Effect; }; /** * Converts an HTTP server effect into a Web `Request` handler using the supplied base context and optional middleware. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toWebHandlerWith: >(context: Context.Context) => (self: Effect.Effect, middleware?: HttpMiddleware | undefined) => [ReqR] extends [never] ? (request: Request, context?: Context.Context | undefined) => Promise : (request: Request, context: Context.Context) => Promise; /** * Converts an HTTP server effect into a Web `Request` handler using an empty base context. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toWebHandler: (self: Effect.Effect, middleware?: HttpMiddleware | undefined) => (request: Request, context?: Context.Context | undefined) => Promise; /** * Builds a Web `Request` handler from a layer and handler factory, returning the handler with a `dispose` function for the layer scope. * * **Details** * * Every call to `dispose` returns the same promise, which resolves once the * layer resources have been released. * * The layer is built immediately, so the cost is paid when the handler is * created rather than on the first request. A layer that performs asynchronous * work while building may still be in progress when the first request arrives, * in which case that request waits for the build to finish. If the build fails, * every request rejects with the build error. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toWebHandlerLayerWith: >(layer: Layer.Layer, options: { readonly toHandler: (context: Context.Context) => Effect.Effect, LE>; readonly middleware?: HttpMiddleware | undefined; readonly memoMap?: Layer.MemoMap | undefined; }) => { readonly dispose: () => Promise; readonly handler: [ReqR] extends [never] ? (request: Request, context?: Context.Context | undefined) => Promise : (request: Request, context: Context.Context) => Promise; }; /** * Builds a Web `Request` handler for an HTTP server effect using a layer to provide its services, returning the handler with a `dispose` function. * * **Details** * * The layer is built immediately, so the cost is paid when the handler is * created rather than on the first request. A layer that performs asynchronous * work while building may still be in progress when the first request arrives, * in which case that request waits for the build to finish. If the build fails, * every request rejects with the build error. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toWebHandlerLayer: >(self: Effect.Effect, layer: Layer.Layer, options?: { readonly middleware?: HttpMiddleware | undefined; readonly memoMap?: Layer.MemoMap | undefined; } | undefined) => { readonly dispose: () => Promise; readonly handler: [ReqR] extends [never] ? (request: Request, context?: Context.Context | undefined) => Promise : (request: Request, context: Context.Context) => Promise; }; /** * Adapts a Web `Request` handler into an HTTP server effect for the current `HttpServerRequest`. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const fromWebHandler: (handler: (request: Request) => Promise) => Effect.Effect; //# sourceMappingURL=HttpEffect.d.ts.map