import { IncomingMessage, ServerResponse } from "http"; import { QueryParams } from "../types/http.js"; import { Readable } from "stream"; /** * Represents the context for a single HTTP request/response cycle. * * Provides convenient helpers for accessing request data (headers, cookies, query, body, etc.) * and for sending responses (status, body, content type, cookies, redirects, downloads, rendering). * * @typeParam TParams - The type of route parameters, defaults to an object with string values. * * @property {boolean} isAuthenticated - Indicates if the request is authenticated. * @property {IncomingMessage} req - The raw Node.js HTTP request object. * @property {ServerResponse} res - The raw Node.js HTTP response object. * @property {TParams} params - Route parameters extracted from the URL. * @property {QueryParams} [query] - Query string parameters. * @property {any} [body] - Parsed request body. * * @method get - Retrieves a request header value by name. * @method header - Alias for `get`. * @method hasHeader - Checks if a request header is present. * @method is - Checks if the request Content-Type matches a given type. * @method ip - Returns the remote IP address. * @method protocol - Returns the protocol ("http" or "https"). * @method secure - Returns true if the protocol is "https". * @method hostname - Returns the hostname from the request. * @method subdomains - Returns an array of subdomains. * @method cookies - Returns parsed cookies as an object. * @method path - Returns the request path. * @method originalUrl - Returns the original request URL. * @method method - Returns the HTTP method. * * @method status - Sets the HTTP response status code. * @method send - Sends a raw response body with a specified content type. * @method text - Sends a plain text response. * @method html - Sends an HTML response. * @method xml - Sends an XML response. * @method json - Sends a JSON response. * @method redirect - Redirects to a different URL. * @method cookie - Sets a cookie in the response. * @method download - Sends a file as a download. * @method render - Renders a template string with data and sends as HTML. * @method renderFile - Renders a template file with data and sends as HTML. */ export declare class Context = {}> { req: IncomingMessage; res: ServerResponse; params: TParams; query?: QueryParams | undefined; body?: any | undefined; isAuthenticated: boolean; constructor(req: IncomingMessage, res: ServerResponse, params: TParams, query?: QueryParams | undefined, body?: any | undefined); get(name: string): string | undefined; header(name: string): string | undefined; hasHeader(name: string): boolean; is(type: string): boolean; get ip(): string; get protocol(): string; get secure(): boolean; get hostname(): string; get subdomains(): string[]; get cookies(): Record; get path(): string; get originalUrl(): string; get method(): string; status(code: number): this; send(body: any, type?: string): void; text(body: string): void; html(body: string): void; xml(body: string): void; json(data: any): void; redirect(url: string, status?: number): void; cookie(name: string, value: string, options?: { path?: string; maxAge?: number; domain?: string; secure?: boolean; httpOnly?: boolean; sameSite?: "Strict" | "Lax" | "None"; }): void; download(filePath: string, filename?: string): void; render(templateStr: string, data?: Record): void; renderFile(filePath: string, data?: Record): void; /** * Stream a readable stream as the response. * This is more memory-efficient than loading the entire content into memory. * * @param stream - The readable stream to pipe to the response * @param options - Optional configuration for content type, filename, and disposition * * @example * ```typescript * const stream = createReadStream('./large-video.mp4'); * ctx.stream(stream, { contentType: 'video/mp4' }); * ``` */ stream(stream: Readable, options?: { contentType?: string; filename?: string; disposition?: "inline" | "attachment"; }): void; /** * Stream a file from disk as the response. * More memory-efficient than reading the entire file into memory. * * @param filePath - Path to the file to stream * @param options - Optional configuration for content type and disposition * * @example * ```typescript * // Stream a large video file * ctx.streamFile('./videos/movie.mp4'); * * // Stream as download * ctx.streamFile('./report.pdf', { disposition: 'attachment' }); * ``` */ streamFile(filePath: string, options?: { contentType?: string; disposition?: "inline" | "attachment"; }): void; } /** * Creates a new Context instance for an incoming HTTP request. * * @param req The Node.js IncomingMessage object. * @param res The Node.js ServerResponse object. * @param query Parsed query parameters from the request URL. * @returns A new Context instance with all request/response helpers initialized. */ export declare function createContext = {}>(req: IncomingMessage, res: ServerResponse, query: QueryParams, params?: TParams, body?: any): Context; //# sourceMappingURL=context.d.ts.map