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

Function shouldProxy

packages/opencode/src/util/proxy-env.ts:50–66  ·  view source on GitHub ↗
(hostname: string, port: number)

Source from the content-addressed store, hash-verified

48}
49
50function shouldProxy(hostname: string, port: number) {
51 const noProxy = env("no_proxy").toLowerCase()
52 if (!noProxy) return true
53 if (noProxy === "*") return false
54
55 return noProxy.split(/[,\s]/).every((proxy) => {
56 if (!proxy) return true
57
58 const parsed = proxy.match(/^(.+):(\d+)$/)
59 const proxyHostname = parsed ? parsed[1] : proxy
60 const proxyPort = parsed ? Number.parseInt(parsed[2]) : 0
61 if (proxyPort && proxyPort !== port) return true
62
63 if (!/^[.*]/.test(proxyHostname)) return hostname !== proxyHostname
64 return !hostname.endsWith(proxyHostname.startsWith("*") ? proxyHostname.slice(1) : proxyHostname)
65 })
66}
67
68function env(key: string) {
69 return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || ""

Callers 1

getProxyForUrlFunction · 0.85

Calls 1

envFunction · 0.70

Tested by

no test coverage detected