(env = process.env)
| 130 | } |
| 131 | |
| 132 | function setGlobalProxyFromEnv(env = process.env) { |
| 133 | validateObject(env, 'proxyEnv'); |
| 134 | const httpProxy = parseProxyUrl(env, 'http:'); |
| 135 | const httpsProxy = parseProxyUrl(env, 'https:'); |
| 136 | const noProxy = env.no_proxy || env.NO_PROXY; |
| 137 | |
| 138 | if (!httpProxy && !httpsProxy) { |
| 139 | return () => {}; |
| 140 | } |
| 141 | |
| 142 | if (httpProxy && !URL.canParse(httpProxy)) { |
| 143 | throw new ERR_PROXY_INVALID_CONFIG(httpProxy); |
| 144 | } |
| 145 | if (httpsProxy && !URL.canParse(httpsProxy)) { |
| 146 | throw new ERR_PROXY_INVALID_CONFIG(httpsProxy); |
| 147 | } |
| 148 | |
| 149 | let originalDispatcher, originalHttpsAgent, originalHttpAgent; |
| 150 | if (httpProxy || httpsProxy) { |
| 151 | // Set it for fetch. |
| 152 | const { setGlobalDispatcher, getGlobalDispatcher, EnvHttpProxyAgent } = lazyUndici(); |
| 153 | const envHttpProxyAgent = new EnvHttpProxyAgent({ |
| 154 | __proto__: null, httpProxy, httpsProxy, noProxy, |
| 155 | }); |
| 156 | originalDispatcher = getGlobalDispatcher(); |
| 157 | setGlobalDispatcher(envHttpProxyAgent); |
| 158 | } |
| 159 | |
| 160 | if (httpProxy) { |
| 161 | originalHttpAgent = module.exports.globalAgent; |
| 162 | module.exports.globalAgent = getGlobalAgent(env, httpAgent.Agent); |
| 163 | } |
| 164 | if (httpsProxy && !!process.versions.openssl) { |
| 165 | const https = require('https'); |
| 166 | originalHttpsAgent = https.globalAgent; |
| 167 | https.globalAgent = getGlobalAgent(env, https.Agent); |
| 168 | } |
| 169 | |
| 170 | return function restore() { |
| 171 | if (originalDispatcher) { |
| 172 | const { setGlobalDispatcher } = lazyUndici(); |
| 173 | setGlobalDispatcher(originalDispatcher); |
| 174 | } |
| 175 | if (originalHttpAgent) { |
| 176 | module.exports.globalAgent = originalHttpAgent; |
| 177 | } |
| 178 | if (originalHttpsAgent) { |
| 179 | require('https').globalAgent = originalHttpsAgent; |
| 180 | } |
| 181 | }; |
| 182 | } |
| 183 | |
| 184 | module.exports = { |
| 185 | _connectionListener, |
nothing calls this directly
no test coverage detected
searching dependent graphs…