| 138 | } |
| 139 | |
| 140 | function getTunnelingAgent(agentOptions, userHttpsAgent) { |
| 141 | const key = |
| 142 | agentOptions.protocol + |
| 143 | '//' + |
| 144 | agentOptions.hostname + |
| 145 | ':' + |
| 146 | (agentOptions.port || '') + |
| 147 | '#' + |
| 148 | (agentOptions.auth || ''); |
| 149 | const cache = userHttpsAgent |
| 150 | ? (tunnelingAgentCacheUser.get(userHttpsAgent) || |
| 151 | tunnelingAgentCacheUser.set(userHttpsAgent, new Map()).get(userHttpsAgent)) |
| 152 | : tunnelingAgentCache; |
| 153 | let agent = cache.get(key); |
| 154 | if (agent) return agent; |
| 155 | // Forward the user's TLS options (custom CA, rejectUnauthorized, client cert, |
| 156 | // etc.) into the tunneling agent so they apply to the origin TLS upgrade |
| 157 | // performed after CONNECT. Our proxy fields take precedence on conflict. |
| 158 | const merged = userHttpsAgent && userHttpsAgent.options |
| 159 | ? { ...userHttpsAgent.options, ...agentOptions } |
| 160 | : agentOptions; |
| 161 | agent = new HttpsProxyAgent(merged); |
| 162 | if (userHttpsAgent && userHttpsAgent.options) { |
| 163 | const originTLSOptions = { ...userHttpsAgent.options }; |
| 164 | const callback = agent.callback; |
| 165 | agent.callback = function axiosTunnelingAgentCallback(req, opts) { |
| 166 | // HttpsProxyAgent v5 reads callback opts for the post-CONNECT origin TLS upgrade. |
| 167 | return callback.call(this, req, { ...originTLSOptions, ...opts }); |
| 168 | }; |
| 169 | } |
| 170 | agent[kAxiosInstalledTunnel] = true; |
| 171 | cache.set(key, agent); |
| 172 | return agent; |
| 173 | } |
| 174 | |
| 175 | const supportedProtocols = platform.protocols.map((protocol) => { |
| 176 | return protocol + ':'; |