11import logger from '/@/logging/logger' ;
22import { getProxyFromPacUrl , invalidatePacCache } from './pacFile' ;
33import { getWindowsProxySettings } from './windowsRegistry' ;
4- import { initializeProxyAgents , tearDownProxyAgents , getCurrentProxyUrl } from './agentManager' ;
4+ import { initializeProxyAgents , tearDownProxyAgents , getCurrentProxyUrl , getCurrentPacUrl } from './agentManager' ;
55
66function normalizeProxyUrl ( url : string ) : string {
77 // If the URL already has a scheme (e.g., http, https, socks4, socks5), return it as-is.
@@ -12,12 +12,19 @@ function normalizeProxyUrl(url: string): string {
1212 return `http://${ url } ` ;
1313}
1414
15- async function getProxyConfiguration ( ) : Promise < string | undefined > {
15+ interface ProxyConfig {
16+ proxyUrl ?: string ;
17+ pacUrl ?: string ;
18+ }
19+
20+ async function getProxyConfiguration ( ) : Promise < ProxyConfig > {
1621 // Check environment variables first
17- const envProxyUrl = process . env . HTTP_PROXY ?? process . env . HTTPS_PROXY ;
22+ const envProxyUrl =
23+ process . env . HTTP_PROXY ?? process . env . HTTPS_PROXY ?? process . env . http_proxy ?? process . env . https_proxy ;
24+
1825 if ( envProxyUrl ) {
1926 logger . log ( `Using proxy from environment: ${ envProxyUrl } ` ) ;
20- return envProxyUrl ;
27+ return { proxyUrl : envProxyUrl } ;
2128 }
2229
2330 // Check Windows Registry
@@ -27,23 +34,24 @@ async function getProxyConfiguration(): Promise<string | undefined> {
2734 if ( proxyServer ) {
2835 const normalizedUrl = normalizeProxyUrl ( proxyServer ) ;
2936 logger . log ( `Using proxy from Windows Registry: ${ normalizedUrl } ` ) ;
30- return normalizedUrl ;
37+ return { proxyUrl : normalizedUrl } ;
3138 }
3239
3340 // PAC file
3441 if ( autoConfigUrl ) {
3542 logger . log ( `Found PAC file URL in registry: ${ autoConfigUrl } ` ) ;
3643 // Query PAC with Chromium download URL as representative for all external access
37- return getProxyFromPacUrl ( autoConfigUrl , 'https://storage.googleapis.com' ) ;
44+ const proxyUrl = await getProxyFromPacUrl ( autoConfigUrl , 'https://storage.googleapis.com' ) ;
45+ return { proxyUrl, pacUrl : autoConfigUrl } ;
3846 }
3947
40- return undefined ;
48+ return { } ;
4149}
4250
4351export async function initProxyIfNeeded ( ) : Promise < void > {
44- const proxyUrl = await getProxyConfiguration ( ) ;
45- if ( proxyUrl ) {
46- initializeProxyAgents ( proxyUrl ) ;
52+ const config = await getProxyConfiguration ( ) ;
53+ if ( config . proxyUrl ) {
54+ initializeProxyAgents ( config . proxyUrl , config . pacUrl ) ;
4755 } else {
4856 logger . log ( 'No proxy configuration found' ) ;
4957 }
@@ -56,9 +64,21 @@ export function tearDownProxy(): void {
5664
5765export function getProxyArgs ( ) : string [ ] {
5866 const proxyUrl = getCurrentProxyUrl ( ) ;
59- if ( proxyUrl ) {
67+ const pacUrl = getCurrentPacUrl ( ) ;
68+ const args : string [ ] = [ ] ;
69+
70+ if ( pacUrl ) {
71+ args . push ( `--proxy-pac-url=${ pacUrl } ` ) ;
72+ } else if ( proxyUrl ) {
6073 const urlObj = new URL ( proxyUrl ) ;
61- return [ `--proxy-server=${ urlObj . host } ` ] ;
74+ args . push ( `--proxy-server=${ urlObj . host } ` ) ;
6275 }
63- return [ ] ;
76+
77+ // Add bypass list from NO_PROXY env var if explicitly set
78+ const noProxy = process . env . NO_PROXY ?? process . env . no_proxy ;
79+ if ( noProxy ) {
80+ args . push ( `--proxy-bypass-list=${ noProxy } ` ) ;
81+ }
82+
83+ return args ;
6484}
0 commit comments