import { ReadableStream } from 'web-streams-polyfill'; import { DataRuntime, DataToolkit, ProgressData, ProgressEventTarget } from './utility'; export declare enum BodyRequestMethods { POST = "POST", PUT = "PUT", PATCH = "PATCH", DELETE = "DELETE" } export interface RequestOptions { withCredentials?: boolean; timeout?: number; responseType?: XMLHttpRequestResponseType; } export interface Request extends RequestOptions { method?: 'HEAD' | 'GET' | keyof typeof BodyRequestMethods; path: string | URL; headers?: HeadersInit; body?: BodyInit | HTMLFormElement | T; signal?: AbortSignal; } export interface Response { status: number; statusText: string; headers: Record; body?: B; } export declare class HTTPError extends URIError { request: Request; response: Response; constructor(message: string, request: Request, response: Response); } export type LinkHeader = Record; export declare const headerParser: { Link: (value: string) => LinkHeader; }; export declare const parseHeaders: (raw: string) => Response["headers"]; export declare function parseBody(raw: string, contentType: string): T; export interface RequestResult { response: Promise>; upload?: AsyncGenerator; download: AsyncGenerator; } /** * Minimum byte count for magic-number–based file type detection, * consistent with the file-type library * {@link https://github.com/sindresorhus/file-type}. */ export declare const FILE_TYPE_MAGIC_NUMBER_SIZE = 4100; export interface HeadResponse { headers: Response['headers']; /** First {@link FILE_TYPE_MAGIC_NUMBER_SIZE} bytes from the response body. */ body?: ArrayBuffer; } export type HTTPRuntime = DataRuntime & Partial>; export declare const defaultHTTPRuntime: HTTPRuntime; export declare class HTTPToolkit extends DataToolkit { runtime: HTTPRuntime; constructor(runtime?: HTTPRuntime); requestXHR: ({ method, path, headers, body, signal, ...rest }: Request) => RequestResult; requestFetch: ({ path, method, headers, withCredentials, body, signal, timeout, responseType }: Request) => RequestResult; parseResponse: ({ status, statusText, headers, body }: globalThis.Response, responseType: Request["responseType"], downloadProgress: ProgressEventTarget) => Promise>; parseFetchBody: (stream: ReadableStream, contentType: string, responseType: Request["responseType"]) => Promise; rawRequest: ({ method, path, headers, body, signal, ...rest }: Request) => RequestResult; /** * Sends a `HEAD` request, falling back to simulation when the server does * not support `HEAD`. Tries, in order: * 1. A standard `HEAD` request via `fetch()`. * 2. A `Range` GET to retrieve the first {@link FILE_TYPE_MAGIC_NUMBER_SIZE} * bytes (magic-number file header). * 3. A plain `GET` that reads the first {@link FILE_TYPE_MAGIC_NUMBER_SIZE} * bytes then cancels the body stream. */ requestHead: ({ path, headers, withCredentials, timeout, signal }: Request) => Promise; /** * Sends a {@link Request}, with automatic HEAD-simulation fallback for * servers that do not support the `HEAD` method. */ request: (option: Request) => RequestResult; } export declare const requestXHR: ({ method, path, headers, body, signal, ...rest }: Request) => RequestResult, requestFetch: ({ path, method, headers, withCredentials, body, signal, timeout, responseType }: Request) => RequestResult, parseResponse: ({ status, statusText, headers, body }: globalThis.Response, responseType: Request["responseType"], downloadProgress: ProgressEventTarget) => Promise>, parseFetchBody: (stream: ReadableStream, contentType: string, responseType: Request["responseType"]) => Promise, rawRequest: ({ method, path, headers, body, signal, ...rest }: Request) => RequestResult, requestHead: ({ path, headers, withCredentials, timeout, signal }: Request) => Promise, request: (option: Request) => RequestResult;