Instructions
Npm install
npm install --save @newstudios/http-utils
Yarn install
yarn add @newstudios/http-utils
Usage notice
The package is a commonjs library, and needs some environments to work as expected
HTTP_BEHIND_PROXY = true
HTTP_FORWARDED_IP_HEADERS = x-forwarded-for
HTTP_MAX_IPS_COUNT = 0
API
export declare function getHeader<F extends string>(req: IncomingMessage, field: F): HeaderType<F>;
export declare function getUserAgent(req: IncomingMessage): string;
export declare function getHost(req: IncomingMessage): string;
export declare function getHostname(req: IncomingMessage): string;
export declare function getURL(req: IncomingMessage): URL;
export declare function getHref(req: IncomingMessage): string;
export declare function getOrigin(req: IncomingMessage): string;
export declare function getProtocol(req: IncomingMessage): string;
export declare function getIps(req: IncomingMessage): string[];
export declare function getIp(req: IncomingMessage): string;
export declare function setIp(req: IncomingMessage, ip: string): void;
export declare function setHeader(res: ServerResponse, field: Record<string, any>): void;
export declare function setHeader(res: ServerResponse, field: string, val: any): void;
export declare function appendHeader(res: ServerResponse, field: string, val: any): void;
export declare function appendHeaders(res: ServerResponse, init: HeadersInit): void;
export declare type SetCookieOptions = Omit<CookieSerializeOptions, 'encode'>;
export declare function getCookie(req: IncomingMessage, name: string): string | undefined;
export declare function setCookie(res: ServerResponse, name: string, val: string, options?: SetCookieOptions): void;
export declare function clearCookie(res: ServerResponse, name: string, options?: SetCookieOptions): void;