(
extra: HttpsProxyAgentOptions<string> = {},
)
| 166 | * scoped to this instance. |
| 167 | */ |
| 168 | export function createAxiosInstance( |
| 169 | extra: HttpsProxyAgentOptions<string> = {}, |
| 170 | ): AxiosInstance { |
| 171 | const proxyUrl = getProxyUrl() |
| 172 | const mtlsAgent = getMTLSAgent() |
| 173 | const instance = axios.create({ proxy: false }) |
| 174 | |
| 175 | if (!proxyUrl) { |
| 176 | if (mtlsAgent) instance.defaults.httpsAgent = mtlsAgent |
| 177 | return instance |
| 178 | } |
| 179 | |
| 180 | const proxyAgent = createHttpsProxyAgent(proxyUrl, extra) |
| 181 | instance.interceptors.request.use(config => { |
| 182 | if (config.url && shouldBypassProxy(config.url)) { |
| 183 | config.httpsAgent = mtlsAgent |
| 184 | config.httpAgent = mtlsAgent |
| 185 | } else { |
| 186 | config.httpsAgent = proxyAgent |
| 187 | config.httpAgent = proxyAgent |
| 188 | } |
| 189 | return config |
| 190 | }) |
| 191 | return instance |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Get or create a memoized proxy agent for the given URI |
no test coverage detected