@@ -13,8 +13,8 @@ import { NodeHttpHandler } from '@smithy/node-http-handler'
1313import { readMacosCertificates , readLinuxCertificates , readWindowsCertificates } from './certificatesReaders'
1414import { Telemetry } from '../../../server-interface'
1515import { OperationalTelemetryProvider , TELEMETRY_SCOPES } from '../../operational-telemetry/operational-telemetry'
16- import { getMacSystemProxy } from './getProxySettings/getMacProxySettings '
17- import { getWindowsSystemProxy } from './getProxySettings/getWindowsProxySettings '
16+ import { pathToFileURL } from 'node:url '
17+ import { execFileSync } from 'node:child_process '
1818
1919export class ProxyConfigManager {
2020 /**
@@ -71,14 +71,35 @@ export class ProxyConfigManager {
7171 return undefined
7272 }
7373
74- private static getSystemProxy ( ) : string | undefined {
75- switch ( process . platform ) {
76- case 'darwin' :
77- return getMacSystemProxy ( ) ?. proxyUrl
78- case 'win32' :
79- return getWindowsSystemProxy ( ) ?. proxyUrl
80- default :
81- return undefined
74+ private static getSystemProxySync ( ) : string | undefined {
75+ try {
76+ const resolved = require . resolve ( 'os-proxy-config' )
77+ const resolvedUrl = pathToFileURL ( resolved ) . href
78+
79+ const snippet = `
80+ (async () => {
81+ try {
82+ const mod = await import(${ JSON . stringify ( resolvedUrl ) } );
83+ const r = await mod.getSystemProxy();
84+ console.log(JSON.stringify(r ?? {}));
85+ } catch (e) {
86+ console.error(e?.message ?? e);
87+ console.log("{}");
88+ }
89+ })();
90+ `
91+
92+ const raw = execFileSync ( process . execPath , [ '-e' , snippet ] , {
93+ encoding : 'utf8' ,
94+ stdio : [ 'ignore' , 'pipe' , 'inherit' ] ,
95+ } )
96+
97+ console . debug ( `os-proxy-config output: ${ raw } ` )
98+ const { proxyUrl } = JSON . parse ( raw . trim ( ) || '{}' )
99+ return proxyUrl && / ^ h t t p s ? : \/ \/ / . test ( proxyUrl ) ? proxyUrl : undefined
100+ } catch ( err ) {
101+ console . warn ( 'os‑proxy‑config shim failed:' , ( err as Error ) . message )
102+ return undefined
82103 }
83104 }
84105
@@ -188,7 +209,7 @@ export class ProxyConfigManager {
188209 }
189210
190211 // Fall back to OS auto‑detect (HTTP or HTTPS only)
191- const sysProxyUrl = ProxyConfigManager . getSystemProxy ( )
212+ const sysProxyUrl = ProxyConfigManager . getSystemProxySync ( )
192213 if ( sysProxyUrl ) {
193214 this . emitProxyMetric ( 'AutoDetect' , certs . length , sysProxyUrl )
194215 return new HttpsProxyAgent ( { ...agentOptions , proxy : sysProxyUrl } )
0 commit comments