use anyhow::Result;
use reqwest::Client;
use std::time::Duration;
#[allow(dead_code)]
pub fn create_optimized_client() -> Result<Client> {
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
let mut headers = HeaderMap::new();
headers.insert(
HeaderName::from_static("http-referer"),
HeaderValue::from_static("https://lc.viwq.dev/"),
);
headers.insert(
HeaderName::from_static("x-title"),
HeaderValue::from_static("lc"),
);
Ok(Client::builder()
.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!(
env!("CARGO_PKG_NAME"),
"/",
env!("CARGO_PKG_VERSION")
))
.default_headers(headers)
.build()?)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_optimized_client_creation() {
let result = create_optimized_client();
assert!(result.is_ok());
let client = result.unwrap();
assert!(format!("{:?}", client).contains("Client"));
}
#[test]
fn test_multiple_optimized_clients() {
let client1 = create_optimized_client();
let client2 = create_optimized_client();
assert!(client1.is_ok());
assert!(client2.is_ok());
}
}