MCPcopy Index your code
hub / github.com/nodejs/node / shouldUseProxy

Method shouldUseProxy

lib/internal/http.js:149–192  ·  view source on GitHub ↗
(hostname, port)

Source from the content-addressed store, hash-verified

147 // See: https://about.gitlab.com/blog/we-need-to-talk-no-proxy
148 // TODO(joyeecheung): share code with undici.
149 shouldUseProxy(hostname, port) {
150 const bypassList = this.bypassList;
151 if (this.bypassList.length === 0) {
152 return true; // No bypass list, always use the proxy.
153 }
154
155 const host = hostname.toLowerCase();
156 const hostWithPort = port ? `${host}:${port}` : host;
157
158 for (let i = 0; i < bypassList.length; i++) {
159 const entry = bypassList[i];
160
161 if (entry === '*') return false; // * bypasses all hosts.
162 if (entry === host || entry === hostWithPort) return false; // Matching host and host:port
163
164 // Follow curl's behavior: strip leading dot before matching suffixes.
165 if (entry[0] === '.') {
166 const suffix = entry.substring(1);
167 if (host === suffix || (host.endsWith(suffix) && host[host.length - suffix.length - 1] === '.')) return false;
168 }
169
170 // Handle wildcards like *.example.com
171 if (entry.startsWith('*.') && host.endsWith(entry.substring(1))) return false;
172
173 // Handle IP ranges (simple format like 192.168.1.0-192.168.1.255)
174 // TODO(joyeecheung): support IPv6.
175 if (entry.includes('-') && isIPv4(host)) {
176 let { 0: startIP, 1: endIP } = entry.split('-');
177 startIP = startIP.trim();
178 endIP = endIP.trim();
179 if (startIP && endIP && isIPv4(startIP) && isIPv4(endIP)) {
180 const hostInt = ipToInt(host);
181 const startInt = ipToInt(startIP);
182 const endInt = ipToInt(endIP);
183 if (hostInt >= startInt && hostInt <= endInt) return false;
184 }
185 }
186
187 // It might be useful to support CIDR notation, but it's not so widely supported
188 // in other tools as a de-facto standard to follow, so we don't implement it for now.
189 }
190
191 return true; // If no matches found, use the proxy.
192 }
193}
194
195function parseProxyUrl(env, protocol) {

Callers 1

checkShouldUseProxyFunction · 0.80

Calls 4

isIPv4Function · 0.85
ipToIntFunction · 0.85
includesMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected