(parsedUrl)
| 2923 | return additionalHeaders[header] || clientHeader || _default; |
| 2924 | } |
| 2925 | _getAgent(parsedUrl) { |
| 2926 | let agent; |
| 2927 | const proxyUrl = pm.getProxyUrl(parsedUrl); |
| 2928 | const useProxy = proxyUrl && proxyUrl.hostname; |
| 2929 | if (this._keepAlive && useProxy) { |
| 2930 | agent = this._proxyAgent; |
| 2931 | } |
| 2932 | if (this._keepAlive && !useProxy) { |
| 2933 | agent = this._agent; |
| 2934 | } |
| 2935 | // if agent is already assigned use that agent. |
| 2936 | if (agent) { |
| 2937 | return agent; |
| 2938 | } |
| 2939 | const usingSsl = parsedUrl.protocol === 'https:'; |
| 2940 | let maxSockets = 100; |
| 2941 | if (this.requestOptions) { |
| 2942 | maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets; |
| 2943 | } |
| 2944 | // This is `useProxy` again, but we need to check `proxyURl` directly for TypeScripts's flow analysis. |
| 2945 | if (proxyUrl && proxyUrl.hostname) { |
| 2946 | const agentOptions = { |
| 2947 | maxSockets, |
| 2948 | keepAlive: this._keepAlive, |
| 2949 | proxy: Object.assign(Object.assign({}, ((proxyUrl.username || proxyUrl.password) && { |
| 2950 | proxyAuth: `${proxyUrl.username}:${proxyUrl.password}` |
| 2951 | })), { host: proxyUrl.hostname, port: proxyUrl.port }) |
| 2952 | }; |
| 2953 | let tunnelAgent; |
| 2954 | const overHttps = proxyUrl.protocol === 'https:'; |
| 2955 | if (usingSsl) { |
| 2956 | tunnelAgent = overHttps ? tunnel.httpsOverHttps : tunnel.httpsOverHttp; |
| 2957 | } |
| 2958 | else { |
| 2959 | tunnelAgent = overHttps ? tunnel.httpOverHttps : tunnel.httpOverHttp; |
| 2960 | } |
| 2961 | agent = tunnelAgent(agentOptions); |
| 2962 | this._proxyAgent = agent; |
| 2963 | } |
| 2964 | // if reusing agent across request and tunneling agent isn't assigned create a new agent |
| 2965 | if (this._keepAlive && !agent) { |
| 2966 | const options = { keepAlive: this._keepAlive, maxSockets }; |
| 2967 | agent = usingSsl ? new https.Agent(options) : new http.Agent(options); |
| 2968 | this._agent = agent; |
| 2969 | } |
| 2970 | // if not using private agent and tunnel agent isn't setup then use global agent |
| 2971 | if (!agent) { |
| 2972 | agent = usingSsl ? https.globalAgent : http.globalAgent; |
| 2973 | } |
| 2974 | if (usingSsl && this._ignoreSslError) { |
| 2975 | // we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process |
| 2976 | // http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options |
| 2977 | // we have to cast it to any and change it directly |
| 2978 | agent.options = Object.assign(agent.options || {}, { |
| 2979 | rejectUnauthorized: false |
| 2980 | }); |
| 2981 | } |
| 2982 | return agent; |
no test coverage detected