MCPcopy Index your code
hub / github.com/AI45Lab/Code / build_reqwest_client

Function build_reqwest_client

core/src/llm/http.rs:262–291  ·  view source on GitHub ↗

Build a reqwest client without consulting system proxy settings. On macOS test runners, the system proxy lookup path can panic inside the `system-configuration` crate when no dynamic store is available. Disabling implicit proxy discovery keeps client construction deterministic while still honoring standard proxy environment variables explicitly.

(
    timeout: Option<Duration>,
    default_headers: Option<reqwest::header::HeaderMap>,
)

Source from the content-addressed store, hash-verified

260/// implicit proxy discovery keeps client construction deterministic while still
261/// honoring standard proxy environment variables explicitly.
262pub(crate) fn build_reqwest_client(
263 timeout: Option<Duration>,
264 default_headers: Option<reqwest::header::HeaderMap>,
265) -> Result<reqwest::Client> {
266 let mut builder = reqwest::Client::builder().no_proxy();
267
268 if let Some(timeout) = timeout {
269 builder = builder.timeout(timeout);
270 }
271
272 if let Some(default_headers) = default_headers {
273 builder = builder.default_headers(default_headers);
274 }
275
276 let proxy_config = explicit_proxy_config_from_env();
277 if let Some(http_proxy) = proxy_config.http.as_deref() {
278 builder = builder.proxy(
279 reqwest::Proxy::http(http_proxy)
280 .with_context(|| format!("Invalid HTTP proxy URL: {http_proxy}"))?,
281 );
282 }
283 if let Some(https_proxy) = proxy_config.https.as_deref() {
284 builder = builder.proxy(
285 reqwest::Proxy::https(https_proxy)
286 .with_context(|| format!("Invalid HTTPS proxy URL: {https_proxy}"))?,
287 );
288 }
289
290 builder.build().context("Failed to build reqwest client")
291}
292
293fn explicit_proxy_config_from_env() -> ExplicitProxyConfig {
294 let http = first_non_empty_env(&["http_proxy", "HTTP_PROXY"]);

Callers 5

newMethod · 0.85
connect_with_timeoutMethod · 0.85
connect_with_timeoutMethod · 0.85

Calls 4

with_contextMethod · 0.80
contextMethod · 0.80
buildMethod · 0.45