import type { BinaryAction } from './asset'; import type { HttpProtocolVersion, InternetProtocolVersion } from './http'; import type { HttpHostSettings } from './settings'; import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'; import type { Readable, Writable } from 'stream'; interface KeepAliveAction { keepAlive?: boolean; agentTimeout?: number; } interface SilentAction { silent?: boolean; } interface ProtocolAction { httpVersion?: HttpProtocolVersion; ipVersion?: InternetProtocolVersion; } export interface IHttpHost { localhost: boolean; hasProtocol(version: HttpProtocolVersion): Promise; upgrade(version: HttpProtocolVersion, altSvc: Undef): void; success(version: HttpProtocolVersion, status?: boolean): number; failed(version: HttpProtocolVersion, status?: boolean): number; error(version: HttpProtocolVersion, status?: boolean): number; didAltSvc(version: HttpProtocolVersion): boolean; nextAltSvc(): boolean; closeAltSvc(error?: boolean): boolean; clearAltSvc(version?: HttpProtocolVersion): void; flagAltSvc(version: HttpProtocolVersion, value: number): void; reset(): void; v2(): boolean; set version(value); get version(): HttpProtocolVersion; get protocol(): string; get secure(): boolean; get hostname(): string; get port(): string; get origin(): string; get streamSize(): number; } export interface HttpHostConstructor { normalizeOrigin(value: string): string; formatBasicAuth(url: URL): string; getBasicAuth(url: URL): Undef; defineLocalHost(values: string[]): void; defineProtocolNegotiation(data: ObjectMap): void; defineHostConfig(settings: HttpHostSettings): void; readonly prototype: IHttpHost; new(url: URL, httpVersion?: HttpProtocolVersion): IHttpHost; } export interface OpenOptions extends KeepAliveAction, SilentAction { host?: IHttpHost; url?: URL; base?: boolean; socketPath?: string; httpVersion?: HttpProtocolVersion; method?: HttpMethod | Lowercase; search?: StringMap; /** @deprecated followRedirect */ follow_redirect?: boolean; followRedirect?: boolean; encoding?: BufferEncoding; maxBufferSize?: number | string; format?: BufferFormat | { out?: BufferFormat; parser?: PlainObject }; headers?: OutgoingHttpHeaders | Headers; signal?: AbortSignal; timeout?: number; pipeTo?: string | Writable; postData?: unknown; connected?: (headers: IncomingHttpHeaders) => Void; statusMessage?: string; progressId?: number | string; outFormat?: { out: BufferFormat; parser?: PlainObject }; outFilename?: Null; outHeaders?: Null; outStream?: Writable; outAbort?: AbortController; } export interface PutOptions extends OpenOptions { contentType?: string; dataEncoding?: BufferEncoding; } export interface PostOptions extends PutOptions { formData?: ArrayOf; } export interface FormDataPart { name?: string; data?: Buffer | Readable | string; value?: unknown; contentType?: string; filename?: string; } export interface Aria2Options extends BinaryAction, SilentAction { pathname?: string; headers?: OutgoingHttpHeaders | Headers; signal?: AbortSignal; } export interface HostConfig extends OpenOptions { host: IHttpHost; url: URL; } export interface ProxySettings extends KeepAliveAction { host: URL; exclude?: string[]; include?: string[]; } export interface RequestInit extends ProtocolAction { headers?: unknown; readTimeout?: number; } export interface ClientConfig { timeout?: number; connectTimeout?: number; redirectLimit?: number; retryWait?: number; retryAfter?: number; retryLimit?: number; } export interface ApplyOptions extends ProtocolAction, PlainObject { client?: ClientConfig; readExpect?: ReadExpectType; acceptEncoding?: boolean; keepAlive?: boolean; } export type HttpMethod = "GET" | "POST" | "PUT" | "HEAD" | "DELETE"; export type BufferFormat = "json" | "yaml" | "json5" | "xml" | "toml"; export type ReadExpectType = "always" | "string" | "none"; export type DataEncodedResult = T extends { encoding: BufferEncoding } ? string : Null; export type DataObjectResult = T extends { format: string | PlainObject } ? Null : DataEncodedResult; export type StatusOnCallback = (code: number, headers: IncomingHttpHeaders, url?: URL) => Void; export type HeadersOnCallback = (headers: IncomingHttpHeaders, url?: URL) => Void;