Skip to content

Commit 5f20dc9

Browse files
committed
fix case where serverHost is not an IP address + refactor
1 parent 2fa8861 commit 5f20dc9

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

doc/environment_variables.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ can be set.
1111
checked in order, and the first one that has a value is used.
1212

1313
* no_grpc_proxy, no_proxy
14-
A comma separated list of comma-separated list of hostnames, IP addresses,
14+
A comma separated list of hostnames, IP addresses,
1515
or CIDR blocks to connect to without using a proxy even
1616
if a proxy is set, for example: no_proxy=example.com,192.168.0.1,192.168.0.0/16.
1717
These variables are checked in order, and the first one

packages/grpc-js/src/http_proxy.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,18 @@ function isIpInCIDR(cidr: CIDRNotation, serverHost: string) {
160160
function hostMatchesNoProxyList(serverHost: string): boolean {
161161
for (const host of getNoProxyHostList()) {
162162
const parsedCIDR = parseCIDR(host);
163+
// host is a CIDR and serverHost is an IP address
164+
if (isIPv4(serverHost) && parsedCIDR && isIpInCIDR(parsedCIDR, serverHost)) {
165+
trace('Not using proxy for target in no_proxy list: ' + serverHost);
166+
return true;
167+
}
163168
// host is a single IP or a domain name suffix
164-
if (!parsedCIDR) {
165-
if (host === serverHost || serverHost.includes(host)) {
169+
else {
170+
if (serverHost.endsWith(host)) {
166171
trace('Not using proxy for target in no_proxy list: ' + serverHost);
167172
return true;
168173
}
169174
}
170-
// host is a CIDR or a domain
171-
else if (isIpInCIDR(parsedCIDR, serverHost)) {
172-
trace('Not using proxy for target in no_proxy list: ' + serverHost);
173-
return true;
174-
}
175175
}
176176
return false;
177177
}

0 commit comments

Comments
 (0)