UNPKG

@tunframework/tun

Version:

tun framework for node with typescript

119 lines (118 loc) 4.07 kB
/// <reference types="node" /> import { IncomingMessage, ServerResponse } from 'http'; import { RAW_REQUEST, RAW_RESPONSE } from './constants/http/symbol.js'; import { mimeExtMap } from './constants/mime.js'; import { TunCookie } from './TunCookie.js'; export declare class TunResponse { #private; [RAW_REQUEST]: IncomingMessage; [RAW_RESPONSE]: ServerResponse; cookies: TunCookie[]; constructor(req: IncomingMessage, res: ServerResponse); get header(): import("http").OutgoingHttpHeaders; get headers(): import("http").OutgoingHttpHeaders; get socket(): import("net").Socket | null; get status(): number; set status(val: number); /** * Get response status message. * By default, it is associated with response.status. */ get message(): string; set message(val: string); set length(val: number); /** * Return response Content-Length as a number when present, * or deduce from ctx.body when possible, or undefined. */ get length(): number; get body(): string | Buffer | import('stream').Stream | Object | Array<any> | null; set body(val: string | Buffer | import('stream').Stream | Object | Array<any> | null); /** * Get a response header field value with case-insensitive field. * * e.g. const etag = ctx.response.get('ETag'); */ get(field: string): string | number | string[] | undefined; /** * Set response header field to value: * * e.g. `ctx.request.set('Cache-Control', 'no-cache');` * ``` * ctx.request.set({ * 'Etag': '1234', * 'Last-Modified': date * }) * ``` */ set(field: string, value: string | number | string[]): void; /** * Append additional header field with value val. */ append(field: string, value: string | number | string[]): void; /** * Remove header field. */ remove(field: string): void; /** * Get request Content-Type void of parameters such as "charset". */ get type(): { mineType?: keyof typeof mimeExtMap; suffixType?: string; rawType?: string; }; set type(val: { mineType?: keyof typeof mimeExtMap; suffixType?: string; rawType?: string; }); /** * Very similar to ctx.request.is(). * Check whether the response type is one of the supplied types. * This is particularly useful for creating middleware that manipulate responses. */ is(...types: string[]): string | false; /** * Perform a [302] redirect to url. * * The string "back" is special-cased to provide Referrer support, * when Referrer is not present alt or "/" is used. */ redirect(url: string, alt: string): void; /** * 设置 响应的 附件下载 Content-Disposition 头,并设置相应 Content-Type 头 * * refers: * https://github.com/jshttp/content-disposition * https://github.com/jshttp/content-disposition/blob/master/index.js */ attachment(filename: string): void; get headerSent(): boolean; /** * Return '' if header not exists * * Set the Last-Modified header as an appropriate UTC string. * You can either set it as a Date or date string. */ get lastModified(): Date | string; set lastModified(date: Date | string); /** * Set the ETag of a response including the wrapped "s. * Note that there is no corresponding response.etag getter. * * e.g. `crypto.createHash('md5').update(ctx.body).digest('hex')` */ get etag(): string; set etag(val: string); /** * 对向CDN缓存服务等 响应 说明区分某个字段的值做两份缓存(gzip|identity)? * * refers: https://imququ.com/post/vary-header-in-http.html */ vary(field: string): void; /** * Flush any set headers, and begin the body. */ flushHeaders(): void; }