Skip to content

Commit a612a76

Browse files
committed
Bring back no-proxy and leverage chromium support for PAC URL directly
1 parent 5fcb453 commit a612a76

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

packages/main/src/backend/proxyConfig/agentManager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import logger from '/@/logging/logger';
88

99
interface ProxyState {
1010
proxyUrl: string;
11+
pacUrl?: string; // Original PAC URL if proxy was resolved from PAC
1112
originalHttpAgent: HttpAgent;
1213
originalHttpsAgent: HttpsAgent;
1314
proxyAgent: ProxyAgent;
@@ -19,7 +20,7 @@ let proxyState: ProxyState | null = null;
1920
let isInitializing = false;
2021
let isTearingDown = false;
2122

22-
export function initializeProxyAgents(proxyUrl: string): void {
23+
export function initializeProxyAgents(proxyUrl: string, pacUrl?: string): void {
2324
if (isInitializing) {
2425
logger.log('Proxy initialization already in progress, ignoring concurrent call');
2526
return;
@@ -57,6 +58,7 @@ export function initializeProxyAgents(proxyUrl: string): void {
5758

5859
proxyState = {
5960
proxyUrl,
61+
pacUrl,
6062
originalHttpAgent: http.globalAgent,
6163
originalHttpsAgent: https.globalAgent,
6264
proxyAgent,
@@ -121,3 +123,7 @@ export function tearDownProxyAgents(): void {
121123
export function getCurrentProxyUrl(): string | null {
122124
return proxyState?.proxyUrl ?? null;
123125
}
126+
127+
export function getCurrentPacUrl(): string | undefined {
128+
return proxyState?.pacUrl;
129+
}
Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logger from '/@/logging/logger';
22
import { getProxyFromPacUrl, invalidatePacCache } from './pacFile';
33
import { getWindowsProxySettings } from './windowsRegistry';
4-
import { initializeProxyAgents, tearDownProxyAgents, getCurrentProxyUrl } from './agentManager';
4+
import { initializeProxyAgents, tearDownProxyAgents, getCurrentProxyUrl, getCurrentPacUrl } from './agentManager';
55

66
function 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

4351
export 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

5765
export 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

Comments
 (0)