Skip to content

Commit 2bc289e

Browse files
authored
revert: refactor auto-discovery for OS proxy settings (#595)" (#604)
This reverts commit 0e68235.
1 parent da5b807 commit 2bc289e

File tree

9 files changed

+63
-552
lines changed

9 files changed

+63
-552
lines changed

package-lock.json

Lines changed: 29 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtimes/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
"hpagent": "^1.2.0",
4646
"jose": "^5.9.6",
4747
"mac-ca": "^3.1.1",
48+
"os-proxy-config": "^1.1.2",
4849
"rxjs": "^7.8.2",
4950
"vscode-languageserver": "^9.0.1",
5051
"vscode-languageserver-protocol": "^3.17.5",
5152
"vscode-uri": "^3.1.0",
52-
"win-ca": "^3.5.1",
53-
"registry-js": "^1.16.1"
53+
"win-ca": "^3.5.1"
5454
},
5555
"devDependencies": {
5656
"@types/mocha": "^10.0.9",

runtimes/runtimes/util/standalone/experimentalProxyUtil.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { NodeHttpHandler } from '@smithy/node-http-handler'
1313
import { readMacosCertificates, readLinuxCertificates, readWindowsCertificates } from './certificatesReaders'
1414
import { Telemetry } from '../../../server-interface'
1515
import { 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

1919
export 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 && /^https?:\/\//.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 })

runtimes/runtimes/util/standalone/getProxySettings/getMacProxySettings.test.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

runtimes/runtimes/util/standalone/getProxySettings/getMacProxySettings.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

runtimes/runtimes/util/standalone/getProxySettings/getWindowsProxySettings.test.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)