Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit 472d790

Browse files
committed
refactor: Expose connection and request timers to builds
1 parent c530039 commit 472d790

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "proton-api-rs"
33
authors = ["Leander Beernaert <lbb-dev@pm.me>"]
4-
version = "0.5.1"
4+
version = "0.5.2"
55
edition = "2021"
66
license = "AGPL-3.0-only"
77
description = "Unofficial implemention of proton REST API in rust"

src/client/client_builder.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ impl ClientBuilder {
110110
self
111111
}
112112

113-
/// Set the request timeout. By default the timeout is set to 5 seconds.
113+
/// Set the request timeout. By default the timeout is set to None.
114114
pub fn request_timeout(mut self, duration: Duration) -> Self {
115115
self.0 = self.0.request_timeout(duration);
116116
self
117117
}
118118

119+
/// Set the connection timeout. By default the timeout is set to None.
120+
pub fn connect_timeout(mut self, duration: Duration) -> Self {
121+
self.0 = self.0.connect_timeout(duration);
122+
self
123+
}
124+
119125
/// Set the proxy for this client. By default no proxy is used
120126
pub fn with_proxy(mut self, proxy: Proxy) -> Self {
121127
self.0 = self.0.with_proxy(proxy);

src/client/http_client/reqwest_client.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub struct HttpClient {
1616
pub struct HttpClientBuilder {
1717
app_version: String,
1818
base_url: String,
19-
request_timeout: Duration,
19+
request_timeout: Option<Duration>,
20+
connect_timeout: Option<Duration>,
2021
user_agent: String,
2122
proxy_url: Option<Proxy>,
2223
}
@@ -33,7 +34,8 @@ impl HttpClientBuilder {
3334
app_version: DEFAULT_APP_VERSION.to_string(),
3435
user_agent: "NoClient/0.1.0".to_string(),
3536
base_url: DEFAULT_HOST_URL.to_string(),
36-
request_timeout: Duration::from_secs(5),
37+
request_timeout: None,
38+
connect_timeout: None,
3739
proxy_url: None,
3840
}
3941
}
@@ -57,9 +59,15 @@ impl HttpClientBuilder {
5759
self
5860
}
5961

60-
/// Set the request timeout. By default the timeout is set to 5 seconds.
62+
/// Set the full request timeout. By default there is no timeout.
6163
pub fn request_timeout(mut self, duration: Duration) -> Self {
62-
self.request_timeout = duration;
64+
self.request_timeout = Some(duration);
65+
self
66+
}
67+
68+
/// Set the connection timeout. By default there is no timeout.
69+
pub fn connect_timeout(mut self, duration: Duration) -> Self {
70+
self.request_timeout = Some(duration);
6371
self
6472
}
6573

@@ -94,11 +102,18 @@ impl HttpClient {
94102
builder = builder.proxy(proxy);
95103
}
96104

105+
if let Some(d) = http_builder.connect_timeout {
106+
builder = builder.connect_timeout(d)
107+
}
108+
109+
if let Some(d) = http_builder.request_timeout {
110+
builder = builder.timeout(d)
111+
}
112+
97113
builder
98114
.min_tls_version(Version::TLS_1_2)
99115
.https_only(true)
100116
.cookie_store(true)
101-
.timeout(http_builder.request_timeout)
102117
.user_agent(http_builder.user_agent)
103118
.default_headers(header_map)
104119
};

0 commit comments

Comments
 (0)