Skip to main content

apollo/
http.rs

1use std::sync::OnceLock;
2use std::time::Duration;
3
4fn build(timeout: Option<Duration>) -> reqwest::Client {
5    let mut builder = reqwest::Client::builder();
6    if let Some(timeout) = timeout {
7        builder = builder.timeout(timeout);
8    }
9    builder.build().unwrap_or_else(|_| reqwest::Client::new())
10}
11
12/// Process-wide client with no explicit timeout.
13pub fn shared() -> reqwest::Client {
14    static CLIENT: OnceLock<reqwest::Client> = OnceLock::new();
15    CLIENT.get_or_init(|| build(None)).clone()
16}
17
18/// Process-wide client with a 30s timeout for ordinary API calls.
19pub fn standard() -> reqwest::Client {
20    static CLIENT: OnceLock<reqwest::Client> = OnceLock::new();
21    CLIENT
22        .get_or_init(|| build(Some(Duration::from_secs(30))))
23        .clone()
24}
25
26/// Process-wide client with a 120s timeout for model inference calls.
27pub fn long() -> reqwest::Client {
28    static CLIENT: OnceLock<reqwest::Client> = OnceLock::new();
29    CLIENT
30        .get_or_init(|| build(Some(Duration::from_secs(120))))
31        .clone()
32}