/// import { ServerResponse } from 'http'; import Request from './Request'; import { ErrorCallback, RServerConfig } from '../@types'; import Logger from './Logger'; export default class Response extends ServerResponse { config: RServerConfig; request: Request; logger: Logger; errorCallback: ErrorCallback | null; startedAt: Date; endedAt: Date; constructor(req: Request); end(cb?: () => void): Promise; end(data?: any, encoding?: string): Promise; /** * sets response header * @param name response header name * @param value response header value */ setHeader(name: string, value: string | number | string[]): this; /** * sets multiple response headers * @param headers object containing response header name value pairs */ setHeaders(headers: { [p: string]: string | number | string[]; }): this; /** * removes a single set response header at a time. function is chainable * @param name response header to remove */ removeHeader(name: string): this; /** * remove response headers that are already set. function is chainable * @param names - comma separated list of header names to remove */ removeHeaders(...names: string[]): this; /** * sets response status code * @param code - the response code */ status(code: number): this; /** * sends json response back to the client. * @param data - the json string or json object which will be stringified */ json(data: object | string): Promise; /** * Redirect client to the given url */ redirect(path: string, status?: number): Promise; /** * sends a file download attachment to the client * @param filePath - relative or absolute file path * @param filename - suggested file download name */ download(filePath: string, filename?: string): Promise; /** * sends json error data back to the client * @param statusCode http error status code, defaults to 400 * @param message short message to return to client * @param errorData error data object, defaults to empty object */ jsonError(statusCode?: number, message?: string, errors?: object): Promise; /** * sends json success data back to the client * @param statusCode http status code, defaults to 200 * @param message short message to return to client * @param successData success data object, default to empty object */ jsonSuccess(statusCode?: number, message?: string, data?: object): Promise; }