@@ -14,6 +14,7 @@ use crate::types::{
1414use crate :: util:: retry:: { retry, RetryPolicy } ;
1515
1616const APPLICATION_OCTET_STREAM : & str = "application/octet-stream" ;
17+ const DEFAULT_TIMEOUT : std:: time:: Duration = std:: time:: Duration :: from_secs ( 10 ) ;
1718
1819/// Thin-client to access a hosted instance of Versioned Storage Service (VSS).
1920/// The provided [`VssClient`] API is minimalistic and is congruent to the VSS server-side API.
3132impl < R : RetryPolicy < E = VssError > > VssClient < R > {
3233 /// Constructs a [`VssClient`] using `base_url` as the VSS server endpoint.
3334 pub fn new ( base_url : String , retry_policy : R ) -> Self {
34- let client = Client :: new ( ) ;
35+ let client = build_client ( ) ;
3536 Self :: from_client ( base_url, client, retry_policy)
3637 }
3738
@@ -45,13 +46,23 @@ impl<R: RetryPolicy<E = VssError>> VssClient<R> {
4546 }
4647 }
4748
49+ /// Constructs a [`VssClient`] from a given [`reqwest::Client`], using `base_url` as the VSS server endpoint.
50+ ///
51+ /// HTTP headers will be provided by the given `header_provider`.
52+ pub fn from_client_and_headers (
53+ base_url : String , client : Client , retry_policy : R ,
54+ header_provider : Arc < dyn VssHeaderProvider > ,
55+ ) -> Self {
56+ Self { base_url, client, retry_policy, header_provider }
57+ }
58+
4859 /// Constructs a [`VssClient`] using `base_url` as the VSS server endpoint.
4960 ///
5061 /// HTTP headers will be provided by the given `header_provider`.
5162 pub fn new_with_headers (
5263 base_url : String , retry_policy : R , header_provider : Arc < dyn VssHeaderProvider > ,
5364 ) -> Self {
54- let client = Client :: new ( ) ;
65+ let client = build_client ( ) ;
5566 Self { base_url, client, retry_policy, header_provider }
5667 }
5768
@@ -162,3 +173,12 @@ impl<R: RetryPolicy<E = VssError>> VssClient<R> {
162173 }
163174 }
164175}
176+
177+ fn build_client ( ) -> Client {
178+ Client :: builder ( )
179+ . timeout ( DEFAULT_TIMEOUT )
180+ . connect_timeout ( DEFAULT_TIMEOUT )
181+ . read_timeout ( DEFAULT_TIMEOUT )
182+ . build ( )
183+ . unwrap ( )
184+ }
0 commit comments