mirror of
https://github.com/grpc/grpc-node.git
synced 2025-12-08 18:23:54 +00:00
fix case where serverHost is not an IP address + refactor
This commit is contained in:
parent
2fa886109b
commit
5f20dc91f0
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user