/// import { ServerResponse as HttpServerResponse } from "http"; import { Readable as StreamReadable } from "stream"; import { IResponseCookie } from "./Responses/IResponseCookie"; import { IResponseHeaders } from "./Responses/IResponseHeaders"; declare class Response { static readonly CODES: { /** * @summary HTTP response code 200 for OK response; */ OK: number; /** * @summary HTTP response code 301 for moved permanently redirection; */ MOVED_PERMANENTLY: number; /** * @summary HTTP response code 303 for see other redirection; */ SEE_OTHER: number; /** * @summary HTTP response code 404 for not found error; */ NOT_FOUND: number; /** * @summary HTTP response code 500 for internal server error; */ INTERNAL_SERVER_ERROR: number; }; /** * @summary Internal header always sent in every response. */ static readonly HEADER_X_CPU_RAM: string; constructor(res: HttpServerResponse); /** * @summary Set HTTP response body. * @param body */ SetBody(body: string): this; /** * @summary Prepend HTTP response body. * @param body */ PrependBody(body: string): this; /** * @summary Append HTTP response body. * @param body */ AppendBody(body: string): this; /** * @summary Get HTTP response body. */ GetBody(): string | null; /** * @summary Returns if response has any `text/html` or `application/xhtml+xml` * substring in `Content-Type` header. */ IsHtmlOutput(): boolean; /** * @summary Returns if response has any `xml` substring in `Content-Type` header. */ IsXmlOutput(): boolean; /** * @summary `true` if body has been sent. */ IsSentBody(): boolean; /** * @summary Send all HTTP headers and send response body. * @param end `true` by default. * @param cb Callback, used only if end param is `true`. */ Send(end?: boolean, cb?: () => void): this; /** * @summary Send response body. * @param end `true` by default. * @param cb Callback, used only if end param is `true`. */ SendBody(end?: boolean, cb?: () => void): this; /** * @summary Set response cookie. * @param cfg */ SetCookie(cfg: IResponseCookie): this; /** * @summary Check if response object has defined given response cookie name. * @param name */ HasCookie(name: string): boolean; /** * @summary Delete cookie - set value to empty string and set expiration to past time. * @param name */ DeleteCookie(name: string): this; /** * @summary `TRUE` if headers has been sent. */ IsSentHeaders(): boolean; /** * @summary Set multiple HTTP response headers as `key => value` object. * All given headers are automatically merged with previously setted headers. * If you change second argument to true, all previous response headers * are removed and given headers will be only headers for output. * There is automatically set response encoding from value for * `Content-Type` header, if contains any `charset=...`. * There is automatically set response encoding from value for * `Content-Encoding` header. * Example: `response.SetHeader(array('Content-Type' => 'text/plain; charset=utf-8'));` * @param headers * @param cleanAllPrevious `false` by default. If `true`, all previously configured headers will be replaced. */ SetHeaders(headers?: IResponseHeaders, cleanAllPrevious?: boolean): this; /** * @summary Set HTTP response header. * There is automatically set response encoding from value for * `Content-Type` header, if contains any `charset=...`. * There is automatically set response encoding from value for * `Content-Encoding` header. * Example: `response.SetHeader('Content-Type', 'text/plain; charset=utf-8');` * @param name * @param value */ SetHeader(name: string, value: number | string | string[] | null): this; /** * @summary Get HTTP response header by name. If header doesn't exists, null is returned. * Example: `response.GetHeader('content-type'); // returns 'text/plain; charset=utf-8'` * @param name */ GetHeader(name: string): number | string | string[] | null; /** * @summary Get if response has any HTTP response header by given `name`. * Example: * `response.GetHeader('Content-Type'); // returns true if there is header 'content-type' * `response.GetHeader('content-type'); // returns true if there is header 'content-type' * @param name */ HasHeader(name: string): boolean; /** * @summary Consolidate all headers from http internal response into local headers list. */ UpdateHeaders(): this; /** * @summary Set disabled headers, never sent except if there is * rendered exception in development environment. * @param disabledHeaders,... */ SetDisabledHeaders(...disabledHeaders: string[]): this; /** * @summary Get disabled headers, never sent except if there is * rendered exception in development environment. */ GetDisabledHeaders(): string[]; /** * @summary Get response protocol HTTP version by request, `HTTP/1.1` by default. */ GetHttpVersion(): string; /** * @summary Set response protocol HTTP version - `HTTP/1.1 | HTTP/2.0`... * @param httpVersion */ SetHttpVersion(httpVersion: string): this; /** * @summary Set HTTP response code. * @param code * @param codeMessage */ SetCode(code: number, codeMessage?: string): this; /** * @summary Get HTTP response code. */ GetCode(): number; /** * @summary Get HTTP response content encoding. * Example: `response.GetEncoding(); // returns 'utf-8'` */ GetEncoding(): string | null; /** * @summary Set HTTP response content encoding. * Example: `response.SetEncoding('utf-8');` * @param encoding */ SetEncoding(encoding?: string): this; /** * @summary Return `true` if response is upgrading response. */ IsUpgrading(): boolean; /** * @summary Return if response has any redirect `"location: ..."` header inside. */ IsRedirect(): boolean; /** * @summary `true` if headers and body has been sent. */ IsSent(): boolean; /** * @summary Send all HTTP headers. * @param code * @param end `false` by default. */ SendHeaders(code?: number, end?: boolean): this; /** * @summary Redirect request to another location. * @param location * @param code * @param reason * @param end `true` by default. */ Redirect(location: string, code?: number, reason?: string, end?: boolean): void; /** * @summary end the request with optional callback. * @param cb */ End(cb?: () => void): void; /** * Event emitter * The defined events on documents including: * 1. close * 2. drain * 3. error * 4. finish * 5. pipe * 6. unpipe */ AddListener(event: "close", listener: () => void): this; AddListener(event: "drain", listener: () => void): this; AddListener(event: "error", listener: (err: Error) => void): this; AddListener(event: "finish", listener: () => void): this; AddListener(event: "pipe", listener: (src: StreamReadable) => void): this; AddListener(event: "unpipe", listener: (src: StreamReadable) => void): this; AddListener(event: string | symbol, listener: (...args: any[]) => void): this; Emit(event: "close"): boolean; Emit(event: "drain"): boolean; Emit(event: "error", err: Error): boolean; Emit(event: "finish"): boolean; Emit(event: "pipe", src: StreamReadable): boolean; Emit(event: "unpipe", src: StreamReadable): boolean; Emit(event: string | symbol, ...args: any[]): boolean; On(event: "close", listener: () => void): this; On(event: "drain", listener: () => void): this; On(event: "error", listener: (err: Error) => void): this; On(event: "finish", listener: () => void): this; On(event: "pipe", listener: (src: StreamReadable) => void): this; On(event: "unpipe", listener: (src: StreamReadable) => void): this; On(event: string | symbol, listener: (...args: any[]) => void): this; Once(event: "close", listener: () => void): this; Once(event: "drain", listener: () => void): this; Once(event: "error", listener: (err: Error) => void): this; Once(event: "finish", listener: () => void): this; Once(event: "pipe", listener: (src: StreamReadable) => void): this; Once(event: "unpipe", listener: (src: StreamReadable) => void): this; Once(event: string | symbol, listener: (...args: any[]) => void): this; PrependListener(event: "close", listener: () => void): this; PrependListener(event: "drain", listener: () => void): this; PrependListener(event: "error", listener: (err: Error) => void): this; PrependListener(event: "finish", listener: () => void): this; PrependListener(event: "pipe", listener: (src: StreamReadable) => void): this; PrependListener(event: "unpipe", listener: (src: StreamReadable) => void): this; PrependListener(event: string | symbol, listener: (...args: any[]) => void): this; PrependOnceListener(event: "close", listener: () => void): this; PrependOnceListener(event: "drain", listener: () => void): this; PrependOnceListener(event: "error", listener: (err: Error) => void): this; PrependOnceListener(event: "finish", listener: () => void): this; PrependOnceListener(event: "pipe", listener: (src: StreamReadable) => void): this; PrependOnceListener(event: "unpipe", listener: (src: StreamReadable) => void): this; PrependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; RemoveListener(event: "close", listener: () => void): this; RemoveListener(event: "drain", listener: () => void): this; RemoveListener(event: "error", listener: (err: Error) => void): this; RemoveListener(event: "finish", listener: () => void): this; RemoveListener(event: "pipe", listener: (src: StreamReadable) => void): this; RemoveListener(event: "unpipe", listener: (src: StreamReadable) => void): this; RemoveListener(event: string | symbol, listener: (...args: any[]) => void): this; Write(chunk: any, encoding: string, cb?: (error: Error | null | undefined) => void): boolean; Pipe(destination: T, options?: { end?: boolean; }): T; } export { Response, IResponseHeaders, IResponseCookie };