MCPcopy
hub / github.com/axios/axios / shouldBypassProxy

Function shouldBypassProxy

lib/helpers/shouldBypassProxy.js:159–210  ·  view source on GitHub ↗
(location)

Source from the content-addressed store, hash-verified

157};
158
159export default function shouldBypassProxy(location) {
160 let parsed;
161
162 try {
163 parsed = new URL(location);
164 } catch (_err) {
165 return false;
166 }
167
168 const noProxy = (process.env.no_proxy || process.env.NO_PROXY || '').toLowerCase();
169
170 if (!noProxy) {
171 return false;
172 }
173
174 if (noProxy === '*') {
175 return true;
176 }
177
178 const port =
179 Number.parseInt(parsed.port, 10) || DEFAULT_PORTS[parsed.protocol.split(':', 1)[0]] || 0;
180
181 const hostname = normalizeNoProxyHost(parsed.hostname.toLowerCase());
182
183 return noProxy.split(/[\s,]+/).some((entry) => {
184 if (!entry) {
185 return false;
186 }
187
188 let [entryHost, entryPort] = parseNoProxyEntry(entry);
189
190 entryHost = normalizeNoProxyHost(entryHost);
191
192 if (!entryHost) {
193 return false;
194 }
195
196 if (entryPort && entryPort !== port) {
197 return false;
198 }
199
200 if (entryHost.charAt(0) === '*') {
201 entryHost = entryHost.slice(1);
202 }
203
204 if (entryHost.charAt(0) === '.') {
205 return hostname.endsWith(entryHost);
206 }
207
208 return hostname === entryHost || (isLoopback(hostname) && isLoopback(entryHost));
209 });
210}

Callers 2

setProxyFunction · 0.85

Calls 3

normalizeNoProxyHostFunction · 0.85
parseNoProxyEntryFunction · 0.85
isLoopbackFunction · 0.85

Tested by

no test coverage detected