* Create an HttpsProxyAgent with optional mTLS configuration * Skips local DNS resolution to let the proxy handle it
(
proxyUrl: string,
extra: HttpsProxyAgentOptions<string> = {},
)
| 133 | * Skips local DNS resolution to let the proxy handle it |
| 134 | */ |
| 135 | function createHttpsProxyAgent( |
| 136 | proxyUrl: string, |
| 137 | extra: HttpsProxyAgentOptions<string> = {}, |
| 138 | ): HttpsProxyAgent<string> { |
| 139 | const mtlsConfig = getMTLSConfig() |
| 140 | const caCerts = getCACertificates() |
| 141 | |
| 142 | const agentOptions: HttpsProxyAgentOptions<string> = { |
| 143 | ...(mtlsConfig && { |
| 144 | cert: mtlsConfig.cert, |
| 145 | key: mtlsConfig.key, |
| 146 | passphrase: mtlsConfig.passphrase, |
| 147 | }), |
| 148 | ...(caCerts && { ca: caCerts }), |
| 149 | } |
| 150 | |
| 151 | if (isEnvTruthy(process.env.CLAUDE_CODE_PROXY_RESOLVES_HOSTS)) { |
| 152 | // Skip local DNS resolution - let the proxy resolve hostnames |
| 153 | // This is needed for environments where DNS is not configured locally |
| 154 | // and instead handled by the proxy (as in sandboxes) |
| 155 | agentOptions.lookup = (hostname, options, callback) => { |
| 156 | callback(null, hostname, getAddressFamily(options)) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return new HttpsProxyAgent(proxyUrl, { ...agentOptions, ...extra }) |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Axios instance with its own proxy agent. Same NO_PROXY/mTLS/CA |
no test coverage detected