UNPKG

@nomicfoundation/hardhat-verify

Version:
55 lines (44 loc) 1.22 kB
import type * as Undici from "undici"; export async function sendGetRequest( url: URL ): Promise<Undici.Dispatcher.ResponseData> { const { request } = await import("undici"); const dispatcher = getDispatcher(); return request(url, { dispatcher, method: "GET", }); } export async function sendPostRequest( url: URL, body: string, headers: Record<string, string> = {} ): Promise<Undici.Dispatcher.ResponseData> { const { request } = await import("undici"); const dispatcher = getDispatcher(); return request(url, { dispatcher, method: "POST", headers, body, }); } let mockDispatcher: Undici.Dispatcher | undefined; function getDispatcher(): Undici.Dispatcher { if (mockDispatcher !== undefined) { return mockDispatcher; } const { ProxyAgent, Agent } = require("undici") as typeof Undici; if (process.env.http_proxy !== undefined) { return new ProxyAgent(process.env.http_proxy); } return new Agent(); } export function setMockDispatcher( dispatcher: Undici.Dispatcher | undefined ): void { mockDispatcher = dispatcher; } export function isSuccessStatusCode(statusCode: number): boolean { return statusCode >= 200 && statusCode <= 299; }