MCPcopy Create free account
hub / github.com/anomalyco/opencode / getProxyForUrl

Function getProxyForUrl

packages/opencode/src/util/proxy-env.ts:36–48  ·  view source on GitHub ↗
(input: string | URL)

Source from the content-addressed store, hash-verified

34}
35
36export 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
50function shouldProxy(hostname: string, port: number) {
51 const noProxy = env("no_proxy").toLowerCase()

Callers

nothing calls this directly

Calls 2

shouldProxyFunction · 0.85
envFunction · 0.70

Tested by

no test coverage detected