Skip to content

Commit 9891a75

Browse files
authored
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
1 parent 077e355 commit 9891a75

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

server/utils/customProxyAgent.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export default async function createCustomProxyAgent(
88
) {
99
const defaultAgent = new Agent({ keepAliveTimeout: 5000 });
1010

11-
const skipUrl = (url: string) => {
12-
const hostname = new URL(url).hostname;
11+
const skipUrl = (url: string | URL) => {
12+
const hostname =
13+
typeof url === 'string' ? new URL(url).hostname : url.hostname;
1314

1415
if (proxySettings.bypassLocalAddresses && isLocalAddress(hostname)) {
1516
return true;
@@ -38,8 +39,7 @@ export default async function createCustomProxyAgent(
3839
dispatch: Dispatcher['dispatch']
3940
): Dispatcher['dispatch'] => {
4041
return (opts, handler) => {
41-
const url = opts.origin?.toString();
42-
return url && skipUrl(url)
42+
return opts.origin && skipUrl(opts.origin)
4343
? defaultAgent.dispatch(opts, handler)
4444
: dispatch(opts, handler);
4545
};
@@ -60,13 +60,10 @@ export default async function createCustomProxyAgent(
6060
':' +
6161
proxySettings.port,
6262
token,
63-
interceptors: {
64-
Client: [noProxyInterceptor],
65-
},
6663
keepAliveTimeout: 5000,
6764
});
6865

69-
setGlobalDispatcher(proxyAgent);
66+
setGlobalDispatcher(proxyAgent.compose(noProxyInterceptor));
7067
} catch (e) {
7168
logger.error('Failed to connect to the proxy: ' + e.message, {
7269
label: 'Proxy',
@@ -95,7 +92,11 @@ export default async function createCustomProxyAgent(
9592
}
9693

9794
function isLocalAddress(hostname: string) {
98-
if (hostname === 'localhost' || hostname === '127.0.0.1') {
95+
if (
96+
hostname === 'localhost' ||
97+
hostname === '127.0.0.1' ||
98+
hostname === '::1'
99+
) {
99100
return true;
100101
}
101102

0 commit comments

Comments
 (0)