export type HttpFetchResponseType = 'json' | 'text' | 'buffer' | 'readable'; export interface HttpFetchOptionsBase { url: string | URL; family?: 4 | 6; method?: string; headers?: HeadersInit; signal?: AbortSignal; timeout?: number; rejectUnauthorized?: boolean; /** * Checks the status code. Defaults to true. */ checkStatusCode?: boolean | ((statusCode: number) => boolean); body?: B | string | ArrayBufferView | any; withCredentials?: boolean; } export interface HttpFetchJsonOptions extends HttpFetchOptionsBase { responseType: 'json'; } export interface HttpFetchBufferOptions extends HttpFetchOptionsBase { responseType: 'buffer'; } export interface HttpFetchDefaultOptions extends HttpFetchOptionsBase { responseType?: undefined; } export interface HttpFetchTextOptions extends HttpFetchOptionsBase { responseType: 'text'; } export interface HttpFetchReadableOptions extends HttpFetchOptionsBase { responseType: 'readable'; } export type HttpFetchOptions = HttpFetchJsonOptions | HttpFetchBufferOptions | HttpFetchDefaultOptions | HttpFetchTextOptions | HttpFetchReadableOptions; export declare function fetchStatusCodeOk(statusCode: number): boolean; export declare function checkStatus(statusCode: number): boolean; export declare function getFetchMethod(options: HttpFetchOptions): string; export interface HttpFetchResponse { statusCode: number; headers: Headers; body: T; } export type fetcher = >(options: T) => Promise ? Buffer : T extends HttpFetchTextOptions ? string : T extends HttpFetchReadableOptions ? M : T extends HttpFetchJsonOptions ? any : Buffer>>; export declare function getHttpFetchAccept(responseType: HttpFetchResponseType | undefined): "application/json" | "text/plain"; export declare function hasHeader(headers: [string, string][], key: string): [string, string]; export declare function removeHeader(headers: [string, string][], key: string): void; export declare function setHeader(headers: [string, string][], key: string, value: string): void; export declare function setDefaultHttpFetchAccept(headers: [string, string][], responseType: HttpFetchResponseType | undefined): void; export declare function createHeadersArray(headers: HeadersInit | undefined): [string, string][]; /** * * @param headers * @param body * @returns Returns the body and Content-Type header that was set. */ export declare function createStringOrBufferBody(headers: [string, string][], body: any): any; export declare function domFetchParseIncomingMessage(response: Response, responseType: HttpFetchResponseType | undefined): Promise; export declare function domFetch>(options: T): Promise ? Buffer : T extends HttpFetchTextOptions ? string : T extends HttpFetchReadableOptions ? Response : T extends HttpFetchJsonOptions ? any : Buffer>>;