From 9891a7577cc0874f41c38ff0e6e5a6b4d8315281 Mon Sep 17 00:00:00 2001 From: Gauthier Date: Wed, 12 Mar 2025 08:25:54 +0100 Subject: [PATCH] fix(proxy): update http proxy to accept bypass list with undici v7 (#1456) With the update of undici to v7, the bypass list of addresses (no_proxy addresses) was not ignored anymore. fix #1454 --- server/utils/customProxyAgent.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/server/utils/customProxyAgent.ts b/server/utils/customProxyAgent.ts index 96ea7fed7..5f163c3de 100644 --- a/server/utils/customProxyAgent.ts +++ b/server/utils/customProxyAgent.ts @@ -8,8 +8,9 @@ export default async function createCustomProxyAgent( ) { const defaultAgent = new Agent({ keepAliveTimeout: 5000 }); - const skipUrl = (url: string) => { - const hostname = new URL(url).hostname; + const skipUrl = (url: string | URL) => { + const hostname = + typeof url === 'string' ? new URL(url).hostname : url.hostname; if (proxySettings.bypassLocalAddresses && isLocalAddress(hostname)) { return true; @@ -38,8 +39,7 @@ export default async function createCustomProxyAgent( dispatch: Dispatcher['dispatch'] ): Dispatcher['dispatch'] => { return (opts, handler) => { - const url = opts.origin?.toString(); - return url && skipUrl(url) + return opts.origin && skipUrl(opts.origin) ? defaultAgent.dispatch(opts, handler) : dispatch(opts, handler); }; @@ -60,13 +60,10 @@ export default async function createCustomProxyAgent( ':' + proxySettings.port, token, - interceptors: { - Client: [noProxyInterceptor], - }, keepAliveTimeout: 5000, }); - setGlobalDispatcher(proxyAgent); + setGlobalDispatcher(proxyAgent.compose(noProxyInterceptor)); } catch (e) { logger.error('Failed to connect to the proxy: ' + e.message, { label: 'Proxy', @@ -95,7 +92,11 @@ export default async function createCustomProxyAgent( } function isLocalAddress(hostname: string) { - if (hostname === 'localhost' || hostname === '127.0.0.1') { + if ( + hostname === 'localhost' || + hostname === '127.0.0.1' || + hostname === '::1' + ) { return true; }