Skip to main content

oxi_agent/tools/
http_client.rs

1//! Shared HTTP client singleton for oxi-agent tools.
2//!
3//! All agent tools that need an HTTP client should use `shared_http_client()`
4//! to reuse the same connection pool and TLS sessions across the process lifetime.
5
6use std::sync::OnceLock;
7
8/// Return a process-lifetime shared `reqwest::Client`.
9///
10/// The client is configured with sensible defaults for tool use:
11/// connection pooling (4 idle conns/host, 30 s idle timeout) and a
12/// 30-second request timeout.
13pub fn shared_http_client() -> &'static reqwest::Client {
14    static CLIENT: OnceLock<reqwest::Client> = OnceLock::new();
15    CLIENT.get_or_init(|| {
16        reqwest::Client::builder()
17            .pool_max_idle_per_host(4)
18            .pool_idle_timeout(std::time::Duration::from_secs(30))
19            .timeout(std::time::Duration::from_secs(30))
20            .build()
21            .expect("HTTP client init failed")
22    })
23}