Elffuss BraidHub

kikocis/continue public

d0cd3fef8227 · 1.3 KiBRawPermalink
1/**
2 * Gets the proxy settings from environment variables
3 * @param protocol The URL protocol (http: or https:)
4 * @returns The proxy URL if available, otherwise undefined
5 */
6export function getProxyFromEnv(protocol: string): string | undefined {
7 if (protocol === "https:") {
8 return (
9 process.env.HTTPS_PROXY ||
10 process.env.https_proxy ||
11 process.env.HTTP_PROXY ||
12 process.env.http_proxy
13 );
14 } else {
15 return process.env.HTTP_PROXY || process.env.http_proxy;
16 }
17}
18
19/**
20 * Checks if a hostname should bypass proxy based on NO_PROXY environment variable
21 * @param hostname The hostname to check
22 * @returns True if the hostname should bypass proxy
23 */
24export function shouldBypassProxy(hostname: string): boolean {
25 const noProxy = process.env.NO_PROXY || process.env.no_proxy;
26 if (!noProxy) return false;
27
28 const noProxyItems = noProxy.split(",").map((item) => item.trim());
29
30 return noProxyItems.some((item) => {
31 // Exact match
32 if (item === hostname) return true;
33
34 // Wildcard domain match (*.example.com)
35 if (item.startsWith("*.") && hostname.endsWith(item.substring(1)))
36 return true;
37
38 // Domain suffix match (.example.com)
39 if (item.startsWith(".") && hostname.endsWith(item.slice(1))) return true;
40
41 return false;
42 });
43}