diff --git a/proxmox-http/src/client/sync.rs b/proxmox-http/src/client/sync.rs index fb10f5be..955a6fce 100644 --- a/proxmox-http/src/client/sync.rs +++ b/proxmox-http/src/client/sync.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::io::Read; use std::sync::Arc; +use std::time::Duration; use anyhow::Error; use http::Response; @@ -12,16 +13,31 @@ use crate::HttpOptions; /// Blocking HTTP client for usage with [`HttpClient`]. pub struct Client { options: HttpOptions, + timeout: Option, } impl Client { pub fn new(options: HttpOptions) -> Self { - Self { options } + Self { + options, + timeout: None, + } + } + + pub fn new_with_timeout(options: HttpOptions, timeout: Duration) -> Self { + Self { + options, + timeout: Some(timeout), + } } fn agent(&self) -> Result { let mut builder = ureq::AgentBuilder::new(); + if let Some(timeout) = self.timeout { + builder = builder.timeout(timeout); + }; + let connector = Arc::new(native_tls::TlsConnector::new()?); builder = builder.tls_connector(connector);