MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / getDispatcherForUrl

Function getDispatcherForUrl

src/utils/proxy-fetch.ts:80–98  ·  view source on GitHub ↗
(targetUrl: string)

Source from the content-addressed store, hash-verified

78 * - undefined when there's no proxy config and the caller can use the global default
79 */
80export function getDispatcherForUrl(targetUrl: string): Dispatcher | undefined {
81 const cfg = readConfig();
82 let parsed: URL;
83 try { parsed = new URL(targetUrl); } catch { return undefined; }
84
85 const candidate = parsed.protocol === 'https:' ? cfg.httpsProxy : cfg.httpProxy;
86 if (!candidate) return undefined;
87 if (shouldBypass(parsed.hostname, cfg.noProxy)) {
88 if (!noProxyDispatcher) noProxyDispatcher = new Agent();
89 return noProxyDispatcher;
90 }
91
92 if (parsed.protocol === 'https:') {
93 if (!httpsDispatcher) httpsDispatcher = new ProxyAgent({ uri: candidate });
94 return httpsDispatcher;
95 }
96 if (!httpDispatcher) httpDispatcher = new ProxyAgent({ uri: candidate });
97 return httpDispatcher;
98}
99
100/**
101 * fetch() drop-in that honors HTTP(S)_PROXY env vars via undici's dispatcher option.

Callers 2

proxyFetchFunction · 0.85

Calls 2

readConfigFunction · 0.85
shouldBypassFunction · 0.85

Tested by

no test coverage detected