http-micro
Version:
Micro-framework on top of node's http module
58 lines (57 loc) • 2.66 kB
TypeScript
/// <reference types="node" />
/// <reference types="content-type" />
import { IApplication } from "./core";
import * as http from "http";
import * as url from "url";
import { RouteContext } from "./route-context";
import * as bodyParser from "./body-parser";
import * as contentType from "content-type";
export declare class Context {
app: IApplication;
req: http.IncomingMessage;
res: http.ServerResponse;
items: Map<string, any>;
requestParser: bodyParser.Parser;
private _contentType;
private _url;
private _ipAddresses;
private _routeContext;
private _bodyParseTask;
constructor(app: IApplication, req: http.IncomingMessage, res: http.ServerResponse, requestParser?: bodyParser.Parser);
getItem<T = any>(key: string): T;
setItem<T = any>(key: string, value: T): void;
hasItem(key: string): boolean;
getUrl(): url.Url;
getRouteContext(): RouteContext;
getRouteParams(): any;
getHttpMethod(): string;
getRequestStream(): http.IncomingMessage;
getResponseStream(): http.ServerResponse;
getRequestBody<T>(parser?: bodyParser.Parser): Promise<T>;
getContentType(): contentType.MediaType;
getClientIpAddress(): string;
getUpstreamIpAddresses(): string[];
getHost(): string;
getProtocol(): string;
isEncrypted(): boolean;
setHeader(key: string, value: string, replace?: boolean): boolean;
setHeaders(headers: any): void;
appendHeaderValue(key: string, value: string, forceAppend?: boolean): void;
removeHeaderValue(key: string, value: string, removeHeaderIfEmpty?: boolean): void;
setContentType(value: string, force?: boolean): void;
setStatus(code: number, message?: string): void;
sendStatus(code: number, message?: string, headers?: any): void;
send(body: any, headers?: any, code?: number): void;
sendText(text: string): void;
sendAsJson(data: any, replacer?: (key: string, value: any) => any, spaces?: string | number): void;
sendNoContent(headers?: any): void;
sendResetContent(headers?: any): void;
sendBadRequest(body: any, headers?: any): void;
sendNotFound(reason?: string, headers?: any): void;
sendForbidden(reason: any, headers?: any): void;
sendMethodNotAllowed(allowedMethods: string[] | string, reason?: string, headers?: any): void;
throw(error: Error): never;
throw(status: number, error: Error): never;
throw(status: number, msg?: string): never;
}
export declare function contextFactory(app: IApplication, req: http.IncomingMessage, res: http.ServerResponse, parser?: bodyParser.Parser): Context;