mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 15:36:52 +00:00
refactor: extract shared proxy-fetch utility from Telegram module
Move makeProxyFetch to src/infra/net/proxy-fetch.ts and add resolveProxyFetchFromEnv which reads standard proxy env vars (HTTPS_PROXY, HTTP_PROXY, and lowercase variants) and returns a proxy-aware fetch via undici's EnvHttpProxyAgent. Telegram re-exports from the shared location to avoid duplication.
This commit is contained in:
committed by
Peter Steinberger
parent
5897eed6e9
commit
ba3fa44c5b
@@ -1,17 +1 @@
|
||||
import { ProxyAgent, fetch as undiciFetch } from "undici";
|
||||
|
||||
export function makeProxyFetch(proxyUrl: string): typeof fetch {
|
||||
const agent = new ProxyAgent(proxyUrl);
|
||||
// undici's fetch is runtime-compatible with global fetch but the types diverge
|
||||
// on stream/body internals. Single cast at the boundary keeps the rest type-safe.
|
||||
// Keep proxy dispatching request-scoped. Replacing the global dispatcher breaks
|
||||
// env-driven HTTP(S)_PROXY behavior for unrelated outbound requests.
|
||||
const fetcher = ((input: RequestInfo | URL, init?: RequestInit) =>
|
||||
undiciFetch(input as string | URL, {
|
||||
...(init as Record<string, unknown>),
|
||||
dispatcher: agent,
|
||||
}) as unknown as Promise<Response>) as typeof fetch;
|
||||
// Return raw proxy fetch; call sites that need AbortSignal normalization
|
||||
// should opt into resolveFetch/wrapFetchWithAbortSignal once at the edge.
|
||||
return fetcher;
|
||||
}
|
||||
export { makeProxyFetch } from "../infra/net/proxy-fetch.js";
|
||||
|
||||
Reference in New Issue
Block a user