1use anyhow::Result;
2use reqwest::Client;
3use std::time::Duration;
4
5#[allow(dead_code)]
8pub fn create_optimized_client() -> Result<Client> {
9 use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
10
11 let mut headers = HeaderMap::new();
13 headers.insert(
14 HeaderName::from_static("http-referer"),
15 HeaderValue::from_static("https://lc.viwq.dev/"),
16 );
17 headers.insert(
18 HeaderName::from_static("x-title"),
19 HeaderValue::from_static("lc"),
20 );
21
22 Ok(Client::builder()
23 .pool_max_idle_per_host(10) .pool_idle_timeout(Duration::from_secs(90)) .tcp_keepalive(Duration::from_secs(60)) .timeout(Duration::from_secs(60)) .connect_timeout(Duration::from_secs(10)) .user_agent(concat!(
32 env!("CARGO_PKG_NAME"),
33 "/",
34 env!("CARGO_PKG_VERSION")
35 ))
36 .default_headers(headers)
38 .build()?)
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_optimized_client_creation() {
47 let result = create_optimized_client();
48 assert!(result.is_ok());
49
50 let client = result.unwrap();
52 assert!(format!("{:?}", client).contains("Client"));
54 }
55
56 #[test]
57 fn test_multiple_optimized_clients() {
58 let client1 = create_optimized_client();
59 let client2 = create_optimized_client();
60
61 assert!(client1.is_ok());
62 assert!(client2.is_ok());
63 }
64}