(targetUrl: string)
| 78 | * - undefined when there's no proxy config and the caller can use the global default |
| 79 | */ |
| 80 | export 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. |
no test coverage detected