| 48 | } |
| 49 | |
| 50 | function 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 | |
| 68 | function env(key: string) { |
| 69 | return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || "" |