import * as dntShim from "./_dnt.shims.js"; import { Status } from "./deps.js"; import type { Request } from "./request.js"; /** The various types of bodies supported when setting the value of `.body` * on a {@linkcode Response} */ export type ResponseBody = string | number | bigint | boolean | symbol | object | undefined | null; /** A function that when invoked returns or resolves to a * {@linkcode ResponseBody}. */ export type ResponseBodyFunction = () => ResponseBody | Promise; /** A symbol that indicates to `response.redirect()` to attempt to redirect * back to the request referrer. For example: * * ```ts * import { Application, REDIRECT_BACK } from "https://deno.land/x/oak/mod.ts"; * * const app = new Application(); * * app.use((ctx) => { * if (ctx.request.url.pathName === "/back") { * ctx.response.redirect(REDIRECT_BACK, "/"); * } * }); * * await app.listen({ port: 80 }); * ``` */ export declare const REDIRECT_BACK: unique symbol; /** An interface to control what response will be sent when the middleware * finishes processing the request. * * The response is usually accessed via the context's `.response` property. * * ### Example * * ```ts * import { Application, Status } from "https://deno.land/x/oak/mod.ts"; * * const app = new Application(); * * app.use((ctx) => { * ctx.response.body = { hello: "oak" }; * ctx.response.type = "json"; * ctx.response.status = Status.OK; * }); * ``` */ export declare class Response { #private; /** The body of the response. The body will be automatically processed when * the response is being sent and converted to a `Uint8Array` or a * `Deno.Reader`. * * Automatic conversion to a `Deno.Reader` occurs for async iterables. */ get body(): ResponseBody | ResponseBodyFunction; /** The body of the response. The body will be automatically processed when * the response is being sent and converted to a `Uint8Array` or a * `Deno.Reader`. * * Automatic conversion to a `Deno.Reader` occurs for async iterables. */ set body(value: ResponseBody | ResponseBodyFunction); /** Headers that will be returned in the response. */ get headers(): dntShim.Headers; /** Headers that will be returned in the response. */ set headers(value: dntShim.Headers); /** The HTTP status of the response. If this has not been explicitly set, * reading the value will return what would be the value of status if the * response were sent at this point in processing the middleware. If the body * has been set, the status will be `200 OK`. If a value for the body has * not been set yet, the status will be `404 Not Found`. */ get status(): Status; /** The HTTP status of the response. If this has not been explicitly set, * reading the value will return what would be the value of status if the * response were sent at this point in processing the middleware. If the body * has been set, the status will be `200 OK`. If a value for the body has * not been set yet, the status will be `404 Not Found`. */ set status(value: Status); /** The media type, or extension of the response. Setting this value will * ensure an appropriate `Content-Type` header is added to the response. */ get type(): string | undefined; /** The media type, or extension of the response. Setting this value will * ensure an appropriate `Content-Type` header is added to the response. */ set type(value: string | undefined); /** A read-only property which determines if the response is writable or not. * Once the response has been processed, this value is set to `false`. */ get writable(): boolean; constructor(request: Request, jsonBodyReplacer?: (key: string, value: unknown) => unknown); /** Add a resource to the list of resources that will be closed when the * request is destroyed. */ addResource(resource: { close(): void; }): void; /** Release any resources that are being tracked by the response. * * @param closeResources close any resource IDs registered with the response */ destroy(closeResources?: boolean): void; /** Sets the response to redirect to the supplied `url`. * * If the `.status` is not currently a redirect status, the status will be set * to `302 Found`. * * The body will be set to a message indicating the redirection is occurring. */ redirect(url: string | URL): void; /** Sets the response to redirect back to the referrer if available, with an * optional `alt` URL if there is no referrer header on the request. If there * is no referrer header, nor an `alt` parameter, the redirect is set to `/`. * * If the `.status` is not currently a redirect status, the status will be set * to `302 Found`. * * The body will be set to a message indicating the redirection is occurring. */ redirect(url: typeof REDIRECT_BACK, alt?: string | URL): void; toDomResponse(): Promise; /** Instead of responding based on the values of the response, explicitly set * the response with a Fetch API `Response`. * * If the response is already finalized, this will throw. You can check * the `.writable` property to determine the state if you are unsure. * * > [!NOTE] * > This will ignore/override values set in the response like the body, * > headers and status, meaning things like cookie management and automatic * > body typing will be ignored. */ with(response: dntShim.Response): void; /** Instead of responding based on the values of the response, explicitly set * the response by providing the initialization to create a Fetch API * `Response`. * * If the response is already finalized, this will throw. You can check * the `.writable` property to determine the state if you are unsure. * * > [!NOTE] * > This will ignore/override values set in the response like the body, * > headers and status, meaning things like cookie management and automatic * > body typing will be ignored. */ with(body?: dntShim.BodyInit | null, init?: dntShim.ResponseInit): void; }