1use std::time::Duration;
4
5use reqwest::Client;
6
7use crate::error::Result;
8
9const DEFAULT_TIMEOUT_SECS: u64 = 30;
11
12pub fn build_http_client(timeout_secs: Option<u64>) -> Result<Client> {
24 let timeout = Duration::from_secs(timeout_secs.unwrap_or(DEFAULT_TIMEOUT_SECS));
25
26 let client = Client::builder()
27 .timeout(timeout)
28 .user_agent(format!("mkt/{}", env!("CARGO_PKG_VERSION")))
29 .gzip(true)
30 .brotli(true)
31 .build()?;
32
33 Ok(client)
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn build_client_with_defaults() {
42 let client = build_http_client(None);
43 assert!(client.is_ok());
44 }
45
46 #[test]
47 fn build_client_with_custom_timeout() {
48 let client = build_http_client(Some(60));
49 assert!(client.is_ok());
50 }
51}