Skip to main content

specado_core/http/
client.rs

1use once_cell::sync::Lazy;
2use reqwest::Client;
3use std::time::Duration;
4
5static HTTP_CLIENT: Lazy<Client> = Lazy::new(|| {
6    Client::builder()
7        .timeout(Duration::from_secs(60))
8        .pool_max_idle_per_host(10)
9        .connect_timeout(Duration::from_secs(10))
10        .build()
11        .expect("Failed to create HTTP client")
12});
13
14pub fn get_client() -> &'static Client {
15    &HTTP_CLIENT
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn returns_same_instance() {
24        let client_a = get_client() as *const Client;
25        let client_b = get_client() as *const Client;
26        assert_eq!(client_a, client_b);
27    }
28}