(input: string | URL)
| 34 | } |
| 35 | |
| 36 | export function getProxyForUrl(input: string | URL) { |
| 37 | const url = typeof input === "string" ? (URL.canParse(input) ? new URL(input) : undefined) : input |
| 38 | if (!url) return |
| 39 | |
| 40 | const protocol = url.protocol.split(":", 1)[0] |
| 41 | const hostname = url.host.replace(/:\d*$/, "") |
| 42 | const port = Number.parseInt(url.port) || DEFAULT_PORTS[protocol] || 0 |
| 43 | if (!shouldProxy(hostname, port)) return |
| 44 | |
| 45 | const proxy = env(`${protocol}_proxy`) || env("all_proxy") |
| 46 | if (!proxy) return |
| 47 | return proxy.includes("://") ? proxy : `${protocol}://${proxy}` |
| 48 | } |
| 49 | |
| 50 | function shouldProxy(hostname: string, port: number) { |
| 51 | const noProxy = env("no_proxy").toLowerCase() |
nothing calls this directly
no test coverage detected