import type EventEmitter from "node:events"; import type UndiciT from "undici"; export declare const DEFAULT_TIMEOUT_IN_MILLISECONDS = 300000; export declare const DEFAULT_MAX_REDIRECTS = 10; export declare const DEFAULT_POOL_MAX_CONNECTIONS = 128; export declare const DEFAULT_USER_AGENT = "Hardhat"; export type Dispatcher = UndiciT.Dispatcher; export type TestDispatcher = UndiciT.MockAgent; export type Interceptable = UndiciT.Interceptable; /** * Options to configure the dispatcher. * * @param timeout The timeout in milliseconds. Defaults to {@link DEFAULT_TIMEOUT_IN_MILLISECONDS}. * @param proxy The proxy to use. If not provided, no proxy is used. * @param pool Whether to use a pool dispatcher. Defaults to `false`. * @param maxConnections The maximum number of connections to use in the pool. Defaults to {@link DEFAULT_POOL_MAX_CONNECTIONS}. * @param isTestDispatcher Whether to use a test dispatcher. Defaults to `false`. It's highly recommended to use a test dispatcher in tests to avoid hanging tests. */ export interface DispatcherOptions { timeout?: number; proxy?: string; pool?: boolean; maxConnections?: number; isTestDispatcher?: boolean; } /** * Options to configure a request. * * @param queryParams The query parameters to append to the url. * @param extraHeaders Additional headers to include in the request. * @param abortSignal The signal to abort the request. */ export interface RequestOptions { queryParams?: Record; extraHeaders?: Record; abortSignal?: AbortSignal | EventEmitter; } export interface HttpResponse { statusCode: number; body: { json(): Promise; text(): Promise; }; } /** * Performs a HTTP request. * * @param url The url to make the request to. * @param requestOptions The options to configure the request. See {@link RequestOptions}. * @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}. * @returns An object containing the status code and the response body. The body can be accessed as JSON or text. * `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`. * @throws ConnectionRefusedError If the connection is refused by the server. * @throws RequestTimeoutError If the request times out. * @throws RequestError If the request fails for any other reason. */ export declare function getRequest(url: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise; /** * Performs a POST request with a JSON body. * * @param url The url to make the request to. * @param body The body of the request, represented as an object. * @param requestOptions The options to configure the request. See {@link RequestOptions}. * @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}. * @returns An object containing the status code and the response body. The body can be accessed as JSON or text. * `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`. * @throws ConnectionRefusedError If the connection is refused by the server. * @throws RequestTimeoutError If the request times out. * @throws RequestError If the request fails for any other reason. */ export declare function postJsonRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise; /** * Performs a POST request with a form body. * * @param url The url to make the request to. * @param body The body of the request, represented as an object. * @param requestOptions The options to configure the request. See {@link RequestOptions}. * @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}. * @returns An object containing the status code and the response body. The body can be accessed as JSON or text. * `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`. * @throws ConnectionRefusedError If the connection is refused by the server. * @throws RequestTimeoutError If the request times out. * @throws RequestError If the request fails for any other reason. */ export declare function postFormRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise; /** * Downloads a file from a url to a destination path. * * @param url The url to download from. * @param destination The absolute path to save the file to. * @param requestOptions The options to configure the request. See {@link RequestOptions}. * @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}. * @throws ConnectionRefusedError If the connection is refused by the server. * @throws RequestTimeoutError If the request times out. * @throws DownloadFailedError If the download fails for any other reason. */ export declare function download(url: string, destination: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise; /** * Creates a dispatcher based on the provided options. * If the `proxy` option is set, it creates a {@link UndiciT.ProxyAgent} dispatcher. * If the `pool` option is set to `true`, it creates a {@link UndiciT.Pool} dispatcher. * Otherwise, it creates a basic {@link UndiciT.Agent} dispatcher. * * @param url The url to make requests to. * @param options The options to configure the dispatcher. See {@link DispatcherOptions}. * @returns The configured dispatcher instance. * @throws DispatcherError If the dispatcher can't be created. */ export declare function getDispatcher(url: string, { timeout, proxy, pool, maxConnections, isTestDispatcher, }?: DispatcherOptions): Promise; export declare function getTestDispatcher(options?: { timeout?: number; }): Promise; /** * Determines whether a proxy should be used for a given url. * * @param url The url to check. * @returns `true` if a proxy should be used for the url, `false` otherwise. */ export declare function shouldUseProxy(url: string): boolean; /** * Determines whether an absolute url is valid. * * @param url The url to check. * @returns `true` if the url is valid, `false` otherwise. */ export declare function isValidUrl(url: string): boolean; /** * Returns the proxy URL from environment variables based on the target URL. * For HTTPS URLs, checks `https_proxy` then `HTTPS_PROXY`. * For HTTP URLs, checks `http_proxy` then `HTTP_PROXY`. * Falls back to the other protocol's proxy if none found. * * @param url The target URL to determine proxy for. * @returns The proxy URL, or `undefined` if none are set. */ export declare function getProxyUrl(url: string): string | undefined; export { ConnectionRefusedError, DispatcherError, DownloadError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js"; //# sourceMappingURL=request.d.ts.map