/// import { OutgoingHttpHeaders } from 'http'; import { Client } from './Client'; export interface CookieOptions { path?: string; domain?: string; expires?: Date; httpOnly?: boolean; maxAge?: number; sameSite?: boolean | 'lax' | 'strict'; secure?: boolean; } export interface Cookie { key: string; value: string; } export declare class Response { private _client; private _body; private _headers; private _code; private _length; private _filePath; private _templatePath; private _templateData; private _buffer; private _cookies; constructor(_client: Client, _body?: string, _headers?: OutgoingHttpHeaders, _code?: number, _length?: number); readonly code: number; readonly body: string; readonly headers: OutgoingHttpHeaders; readonly cookies: (Cookie & CookieOptions)[]; readonly contentLength: number; readonly filePath: string | null; readonly templatePath: string | null; readonly templateData: {} | null; readonly buffer: Buffer | null; /** * Sets the length in bytes of the response * * @param {number} length The number of bytes * @returns * @memberof Response */ setContentLength(length: number): this; /** * Sets the status code for the http response * * @param {number} code The code number to use * @returns * @memberof Response */ setCode(code: number): this; /** * Sets the body of the http response * * @param {string} body The body data * @returns * @memberof Response */ setBody(body: string): this; /** * Sets the body data as a buffer instead of a string * * @param {Buffer} data The buffer to use * @returns * @memberof Response */ setBuffer(data: Buffer): this; /** * Sets the path of the file to use for a download or stream * * @param {string} path The path to the file on the server * @returns * @memberof Response */ setFile(path: string): this; /** * Removes all of the headers in the response * * @returns * @memberof Response */ clearHeaders(): this; /** * Sets the headers all at once replacing old headers with new values if they exist * * @param {OutgoingHttpHeaders} headers * @returns * @memberof Response */ setHeaders(headers: OutgoingHttpHeaders): this; /** * Sets a single header replacing the old header if it exists * * @param {string} key The key portion of the header such as `Content-Type` * @param {string} value The value portion of the header such as `text/html` * @returns * @memberof Response */ setHeader(key: string, value: string): this; /** * Checks to see if a header exists in the current list of response headers * * @param {string} key The key of the header such as `Content-Type` * @returns {boolean} * @memberof Response */ hasHeader(key: string): boolean; /** * Sets a cookie on the clients browser * * @param {string} key The cookie key * @param {string} value The cookie value * @param {CookieOptions} options Cookie settings such as the path, domain, expiration, etc. * @returns * @memberof Response */ setCookie(key: string, value: string, options: CookieOptions): this; /** * Deletes a cookie from the clients browser * * @param {string} key The key for the cookie * @param {CookieOptions} [options] Optional options for the cookie, any expire option will be overwritten. * @returns * @memberof Response */ deleteCookie(key: string, options?: CookieOptions): this; /** * Renders a template. * * @param {string} path The location to the template * @param {{}} [data={}] Additional data for the template such as functions/variables * @param {number} [code=200] The status code to send with the template * @returns * @memberof Response */ render(path: string, data?: {}, code?: number): this; /** * Sends JSON data to the client. The content-type will automatically be set as `application/json`. * * @param {*} data The data to send * @param {number} [code=200] The status code to send with the data * @returns * @memberof Response */ json(data: any, code?: number): this; /** * Sends HTML to the client. The content-type will automatically be set as `text/html`. * * @param {string} data The html to set along with the response * @param {number} [code=200] The status code to send with the html * @returns * @memberof Response */ html(data: string, code?: number): this; /** * Sends a file to the client to download. The content-type will automatically be set by analyzing the file extension; * along with that, `content-disposition` will also be set. * * @param {string} name The name the file should be saved as * @param {Buffer} data The data to send to the client * @param {number} [code=200] The status code to send with the download * @returns * @memberof Response */ download(name: string, data: Buffer, code?: number): this; /** * Sends a file to the client to download. The content-type will automatically be set by analyzing the file extension; * along with that, `content-disposition` will also be set. * * @param {string} name The name the file should be saved as * @param {string} path The location to the file on the server * @param {number} [code=200] The status code to send with the download * @returns * @memberof Response */ download(name: string, path: string, code?: number): this; /** * Redirects a user to a new location * * @readonly * @memberof Response */ readonly redirect: { /** * Redirects to a named route * * @param {string} name * @param {{ * params: { [key: string]: any }, * query: { [key: string]: any } * }} [options={}] * @returns */ to(name: string, options?: { params?: { [key: string]: any; } | undefined; query?: { [key: string]: any; } | undefined; body?: string | undefined; headers?: OutgoingHttpHeaders | undefined; }): Response; /** * Redirects to a new URL this can be an internal or external location * * @param {string} path The url or path to redirect to * @returns */ location(path: string, options?: { body?: string | undefined; headers?: OutgoingHttpHeaders | undefined; }): Response; }; }