fix case where serverHost is not an IP address + refactor

This commit is contained in:
Malak El Kouri 2025-01-10 10:39:20 +01:00
parent 2fa886109b
commit 5f20dc91f0
2 changed files with 8 additions and 8 deletions

View File

@ -11,7 +11,7 @@ can be set.
checked in order, and the first one that has a value is used.
* no_grpc_proxy, no_proxy
A comma separated list of comma-separated list of hostnames, IP addresses,
A comma separated list of hostnames, IP addresses,
or CIDR blocks to connect to without using a proxy even
if a proxy is set, for example: no_proxy=example.com,192.168.0.1,192.168.0.0/16.
These variables are checked in order, and the first one

View File

@ -160,18 +160,18 @@ function isIpInCIDR(cidr: CIDRNotation, serverHost: string) {
function hostMatchesNoProxyList(serverHost: string): boolean {
for (const host of getNoProxyHostList()) {
const parsedCIDR = parseCIDR(host);
// host is a CIDR and serverHost is an IP address
if (isIPv4(serverHost) && parsedCIDR && isIpInCIDR(parsedCIDR, serverHost)) {
trace('Not using proxy for target in no_proxy list: ' + serverHost);
return true;
}
// host is a single IP or a domain name suffix
if (!parsedCIDR) {
if (host === serverHost || serverHost.includes(host)) {
else {
if (serverHost.endsWith(host)) {
trace('Not using proxy for target in no_proxy list: ' + serverHost);
return true;
}
}
// host is a CIDR or a domain
else if (isIpInCIDR(parsedCIDR, serverHost)) {
trace('Not using proxy for target in no_proxy list: ' + serverHost);
return true;
}
}
return false;
}