mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-01 19:03:42 +00:00
fix(core): respect NO_PROXY in global fetch dispatcher (#27216)
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
import { getErrorMessage, isAbortError } from './errors.js';
|
||||
import { URL } from 'node:url';
|
||||
import { Agent, ProxyAgent, setGlobalDispatcher } from 'undici';
|
||||
import { Agent, EnvHttpProxyAgent, setGlobalDispatcher } from 'undici';
|
||||
import ipaddr from 'ipaddr.js';
|
||||
import { lookup } from 'node:dns/promises';
|
||||
|
||||
@@ -169,11 +169,21 @@ export async function isPrivateIpAsync(url: string): Promise<boolean> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an undici ProxyAgent that incorporates safe DNS lookup.
|
||||
* Creates an undici EnvHttpProxyAgent that incorporates safe DNS lookup.
|
||||
*/
|
||||
export function createSafeProxyAgent(proxyUrl: string): ProxyAgent {
|
||||
return new ProxyAgent({
|
||||
uri: proxyUrl,
|
||||
export function createSafeProxyAgent(proxyUrl: string): EnvHttpProxyAgent {
|
||||
const trimmedProxy = proxyUrl.trim();
|
||||
const noProxy = (
|
||||
process.env['NO_PROXY'] ??
|
||||
process.env['no_proxy'] ??
|
||||
''
|
||||
)?.trim();
|
||||
return new EnvHttpProxyAgent({
|
||||
httpProxy: trimmedProxy,
|
||||
httpsProxy: trimmedProxy,
|
||||
noProxy,
|
||||
headersTimeout: defaultHeadersTimeout,
|
||||
bodyTimeout: defaultBodyTimeout,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -220,10 +230,18 @@ export async function fetchWithTimeout(
|
||||
}
|
||||
|
||||
export function setGlobalProxy(proxy: string) {
|
||||
currentProxy = proxy;
|
||||
const trimmedProxy = proxy.trim();
|
||||
currentProxy = trimmedProxy;
|
||||
const noProxy = (
|
||||
process.env['NO_PROXY'] ??
|
||||
process.env['no_proxy'] ??
|
||||
''
|
||||
)?.trim();
|
||||
setGlobalDispatcher(
|
||||
new ProxyAgent({
|
||||
uri: proxy,
|
||||
new EnvHttpProxyAgent({
|
||||
httpProxy: trimmedProxy,
|
||||
httpsProxy: trimmedProxy,
|
||||
noProxy,
|
||||
headersTimeout: defaultHeadersTimeout,
|
||||
bodyTimeout: defaultBodyTimeout,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user