runtime/globals/fetch/
client.rs1use std::sync::OnceLock;
8use std::time::Duration;
9
10use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
11use hyper_util::client::legacy;
12use hyper_util::client::legacy::connect::HttpConnector;
13use hyper_util::rt::TokioExecutor;
14
15use crate::globals::fetch::body::Body;
16
17pub type Client = legacy::Client<HttpsConnector<HttpConnector>, Body>;
18
19pub static GLOBAL_CLIENT: OnceLock<Client> = OnceLock::new();
20
21pub fn default_client() -> Client {
22 let https = HttpsConnectorBuilder::new().with_webpki_roots().https_or_http().enable_http1().build();
23
24 let mut client = legacy::Client::builder(TokioExecutor::default());
25
26 client.pool_idle_timeout(Duration::from_secs(60));
27 client.pool_max_idle_per_host(usize::MAX);
28 client.retry_canceled_requests(true);
29 client.set_host(false);
30
31 client.build(https)
32}