Skip to content

Commit 3465c9f

Browse files
authored
Merge pull request #39 from tnull/2025-08-enable-client-side-delays
Enable client-side timeouts and replace retry logic with `reqwest`'s
2 parents 98ac5e1 + 23097bf commit 3465c9f

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/client.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::types::{
1414
use crate::util::retry::{retry, RetryPolicy};
1515

1616
const 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.
@@ -31,7 +32,7 @@ where
3132
impl<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+
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#![deny(rustdoc::private_intra_doc_links)]
1212
#![deny(missing_docs)]
1313

14+
// Crate re-exports
15+
pub use reqwest;
16+
1417
/// Implements a thin-client ([`client::VssClient`]) to access a hosted instance of Versioned Storage Service (VSS).
1518
pub mod client;
1619

tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ mod tests {
221221
message: "NoSuchKeyException".to_string(),
222222
};
223223
let mock_server = mockito::mock("POST", GET_OBJECT_ENDPOINT)
224-
.with_status(409)
224+
.with_status(404)
225225
.with_body(&error_response.encode_to_vec())
226226
.create();
227227

0 commit comments

Comments
 (0)