UNPKG

@glandjs/http

Version:

A protocol adapter for HTTP built on top of the Gland architecture solution.

65 lines (64 loc) 4.03 kB
import { Context } from "@glandjs/core"; import { HttpEventCore } from "../adapter/http-events"; import { HttpExceptionOptions, HttpStatus, type Dictionary, type Maybe } from "@medishn/toolkit"; import type { ContentType, CookieOptions, ErrorCallback, HttpHeaderName, HttpHeaderValue, SendOptions } from "../interface"; import type { RequestMethod } from "../enum"; import type { EventRecord } from "@glandjs/events"; export type AcceptType = ContentType | string[]; export declare abstract class HttpContext<TRequest = any, TResponse = any, TEvents extends EventRecord = EventRecord> extends Context<TEvents> { protected readonly events: HttpEventCore<TEvents>; readonly req: TRequest; readonly res: TResponse; params: Dictionary<string>; host?: Maybe<string>; constructor(events: HttpEventCore<TEvents>, req: TRequest, res: TResponse); abstract get body(): any; abstract get path(): string; abstract get xhr(): boolean; abstract get stale(): boolean; abstract get fresh(): boolean; abstract get method(): RequestMethod; abstract get hostname(): string; abstract get ip(): string | undefined; abstract get protocol(): string; abstract get secure(): boolean; abstract get url(): string; abstract get originalUrl(): string; abstract get query(): Dictionary<string | string[] | undefined>; abstract get subdomains(): string[]; abstract get accepts(): (types?: AcceptType) => string | false; abstract get is(): (type: string | string[]) => string | false | null; abstract status(code: HttpStatus): this; abstract redirect(url: string): this; abstract setCookie(name: string, value: string, options?: CookieOptions): this; abstract clearCookie(name: string, options?: Partial<CookieOptions>): this; abstract getCookie(name: string): Maybe<string>; abstract deleteCookie(name: string, options?: Partial<CookieOptions>): void; abstract get cookies(): Dictionary<string>; abstract get signedCookies(): Dictionary<string>; abstract send(data: any, statusCode?: number, headers?: Dictionary<HttpHeaderName | HttpHeaderName[]>): this; abstract json(data: any, statusCode?: number, headers?: Dictionary<HttpHeaderName | HttpHeaderName[]>): this; abstract html(html: string, statusCode?: number, headers?: Dictionary<HttpHeaderName | HttpHeaderName[]>): this; abstract text(text: string, statusCode?: number, headers?: Dictionary<HttpHeaderName | HttpHeaderName[]>): this; abstract xml(xml: string, statusCode?: number, headers?: Dictionary<HttpHeaderName | HttpHeaderName[]>): this; abstract format(formatters: Dictionary<() => void>): this; throw(status: HttpStatus, options?: HttpExceptionOptions): this; abstract sendFile(filePath: string, options?: SendOptions, fn?: ErrorCallback): this; abstract jsonp(data: any): this; abstract sse(): this; abstract download(filePath: string, filename: string, options?: SendOptions): this; abstract render(view: string, options?: Dictionary<any>, callback?: (err: Error, html: string) => void): this; abstract end(): this; abstract hasHeader(name: HttpHeaderName): boolean; abstract getHeader<T extends string, THeaders extends string>(name: HttpHeaderName<T>): HttpHeaderValue<T, THeaders> | undefined; abstract getHeader(name: string): string | string[] | undefined; abstract getHeader(name: HttpHeaderName): string | string[] | undefined; abstract setHeader<T extends string, THeaders extends string>(name: HttpHeaderName<T>, value: HttpHeaderValue<T, THeaders>): this; abstract setHeader(name: HttpHeaderName, value: any): this; abstract setHeaders(headers: Dictionary<HttpHeaderName | HttpHeaderName[]>): this; abstract removeHeader<T extends string>(name: HttpHeaderName<T, string>): this; abstract get headers(): Dictionary<string | string[]>; abstract vary(fields: string): this; abstract attachment(filename?: string): this; abstract location(url: string): this; }