UNPKG

@uploadx/core

Version:
62 lines (61 loc) 2.64 kB
import http from 'http'; import { Headers, IncomingMessageWithBody, ResponseBody, ResponseTuple, UploadxResponse } from '../types'; export declare const typeis: { (req: http.IncomingMessage, types: string[]): string | false; is(mime: string, types?: string[]): string | false; hasBody(req: http.IncomingMessage): number | false; }; /** * Reads the body from the request. * @param req - request object * @param encoding - encoding to use * @param limit - optional limit on the size of the body */ export declare function readBody(req: http.IncomingMessage, encoding?: BufferEncoding, limit?: number): Promise<string>; /** * Reads the body of the incoming metadata request and parses it as JSON. * @param req - incoming metadata request * @param limit - optional limit on the size of the body */ export declare function getJsonBody(req: IncomingMessageWithBody<Record<any, any>>, limit?: number): Promise<Record<any, any>>; /** * Retrieve the value of a specific header of an HTTP request. * @param req - request object * @param name - name of the header * @param all - if true, returns all values of the header, comma-separated, otherwise returns the last value. */ export declare function getHeader(req: http.IncomingMessage, name: string, all?: boolean): string; /** * Appends value to the end of the multi-value header */ export declare function appendHeader(res: http.ServerResponse, name: string, value: http.OutgoingHttpHeader): void; /** * Sets the value of a specific header of an HTTP response. */ export declare function setHeaders(res: http.ServerResponse, headers?: Headers): void; /** * Try build a protocol:hostname:port string from a request object. */ export declare function getBaseUrl(req: http.IncomingMessage): string; /** * Extracts host with port from a http or https request. */ export declare function extractHost(req: http.IncomingMessage & { host?: string; hostname?: string; }): string; /** * Extracts protocol from a http or https request. */ export declare function extractProto(req: http.IncomingMessage): string; export declare function responseToTuple<T extends ResponseBody>(response: UploadxResponse<T> | ResponseTuple<T>): ResponseTuple; export declare function tupleToResponse<T extends ResponseBody>(response: ResponseTuple<T> | UploadxResponse<T>): UploadxResponse; export declare function normalizeHookResponse<T>(fn: (file: T) => Promise<UploadxResponse>): (file: T) => Promise<{ statusCode: number | undefined; headers: Headers | undefined; body: ResponseBody; } | { body: never; statusCode?: undefined; headers?: undefined; }>;