(location)
| 157 | }; |
| 158 | |
| 159 | export 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 | } |
no test coverage detected