import { IncomingHttpHeaders, IncomingMessage, OutgoingMessage } from 'node:http'; import { StreamFileOptions } from './declarations.js'; import { OutgoingHttpResponse } from './OutgoingHttpResponse.js'; import { File, UploadedFile } from '@stone-js/filesystem'; /** * Decorator response callback. * * @param target - The target function. * @param responseCallback - The response callback. * @returns The function with the response callback. */ /** * Record, on the class, the status the decorated method answers with. * * The decorator already knows it: the author wrote `@JsonHttpResponse(201)` once. Without this the * knowledge lived only inside the wrapped function, so anything reading the class, a generated * contract above all, had to assume `200` and contradicted the code it was derived from. * * Declaring it changes nothing at run time. It is what makes "the code is the single description" * true for the status as well as for the payload. * * @param context - The method decorator context. * @param statusCode - The status the method answers with. */ export declare function declareResponseStatus(context: ClassMethodDecoratorContext, statusCode: number): void; export declare function decoratorResponseCallback(target: TTarget, responseCallback: (content: any) => Promise): TFunction; /** * Check if multipart message. * * @param value - The incoming message or content type string. * @returns True if the content type is multipart. */ export declare function isMultipart(value: IncomingMessage | string): boolean; /** * Get message content type. * * @param value - The incoming message or content type string. * @param fallback - Fallback content type if parsing fails. * @returns The content type of the message. */ export declare function getType(value: IncomingMessage | string, fallback?: string): string; /** * Get message content charset. * * @param value - The incoming message or content type string. * @param fallback - Fallback charset if parsing fails. * @returns The charset of the message. */ export declare function getCharset(value: IncomingMessage | string, fallback?: string): string; /** * Check if IP is trusted or not. * * @param trusted - Array of trusted IPs or wildcard. * @param untrusted - Array of untrusted IPs or wildcard. * @returns A function to verify if a given IP is trusted. */ export declare function isIpTrusted(trusted: string | string[], untrusted?: string | string[]): (ip: string) => boolean; /** * Get protocol. * * @param ip - The IP address of the request. * @param headers - The headers from the incoming request. * @param encrypted - Whether the connection is encrypted (HTTPS). * @param options - Options for trusted and untrusted IPs. * @returns The protocol (http or https). */ export declare function getProtocol(ip: string, headers: IncomingHttpHeaders, encrypted: boolean, { trustedIp, untrustedIp }: { trustedIp: string[]; untrustedIp: string[]; }): string; /** * Validate hostname. * * @param hostname - The hostname to validate. * @returns True if the hostname is valid, false otherwise. */ export declare function isValidHostname(hostname: string): boolean; /** * Get hostname. * * @param ip - The IP address of the request. * @param headers - The headers from the incoming request. * @param options - Options for trusted IPs, fallback, etc. * @returns The hostname from the request. */ export declare function getHostname(ip: string, headers: IncomingHttpHeaders, { trusted, trustedIp, untrustedIp }: { trusted: Array; trustedIp: string[]; untrustedIp: string[]; }): string | undefined; /** * Get file uploads. * * Get streamed or pre-read(not streamed) file upload. * * @param event - The incoming event containing the file data. * @param options - The options for file upload limits. * @returns A promise that resolves with the uploaded files and fields. */ export declare function getFilesUploads(event: IncomingMessage | { headers: IncomingHttpHeaders; body: unknown; }, options: Record): Promise<{ files: Record; fields: Record; }>; /** * Stream files from the file system as an HTTP response. * * Only for node http server. * * @param message - The incoming message. * @param response - The outgoing response. * @param fileResponse - The binary file response to be streamed. * @param options - The options for streaming. * @returns A promise that resolves when the file streaming is complete. */ export declare function streamFile(message: IncomingMessage, response: OutgoingMessage, fileResponse: File, options: StreamFileOptions): Promise;