@@ -43,8 +43,8 @@ use crate::http_client::DEFAULT_REQUEST_TIMEOUT;
43
43
/// ```
44
44
#[ derive( Copy , Clone ) ]
45
45
pub struct RequestConfig {
46
- pub ( crate ) timeout : Duration ,
47
46
pub ( crate ) timeout : Option < Duration > ,
47
+ pub ( crate ) read_timeout : Option < Duration > ,
48
48
pub ( crate ) retry_limit : Option < usize > ,
49
49
pub ( crate ) max_retry_time : Option < Duration > ,
50
50
pub ( crate ) max_concurrent_requests : Option < NonZeroUsize > ,
@@ -57,6 +57,7 @@ impl Debug for RequestConfig {
57
57
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
58
58
let Self {
59
59
timeout,
60
+ read_timeout,
60
61
retry_limit,
61
62
max_retry_time : retry_timeout,
62
63
force_auth,
@@ -66,6 +67,7 @@ impl Debug for RequestConfig {
66
67
67
68
let mut res = fmt. debug_struct ( "RequestConfig" ) ;
68
69
res. field ( "timeout" , timeout)
70
+ . maybe_field ( "read_timeout" , read_timeout)
69
71
. maybe_field ( "retry_limit" , retry_limit)
70
72
. maybe_field ( "max_retry_time" , retry_timeout)
71
73
. maybe_field ( "max_concurrent_requests" , max_concurrent_requests)
@@ -82,8 +84,8 @@ impl Debug for RequestConfig {
82
84
impl Default for RequestConfig {
83
85
fn default ( ) -> Self {
84
86
Self {
85
- timeout : DEFAULT_REQUEST_TIMEOUT ,
86
87
timeout : Some ( DEFAULT_REQUEST_TIMEOUT ) ,
88
+ read_timeout : None ,
87
89
retry_limit : Default :: default ( ) ,
88
90
max_retry_time : Default :: default ( ) ,
89
91
max_concurrent_requests : Default :: default ( ) ,
@@ -139,6 +141,20 @@ impl RequestConfig {
139
141
self
140
142
}
141
143
144
+ /// Set the read timeout duration for all HTTP requests.
145
+ ///
146
+ /// The timeout applies to each read operation, and resets after a
147
+ /// successful read. This is more appropriate for detecting stalled
148
+ /// connections when the size isn’t known beforehand.
149
+ ///
150
+ /// **IMPORTANT**: note this value can only be applied when the HTTP client
151
+ /// is instantiated, it won't have any effect on a per-request basis.
152
+ #[ must_use]
153
+ pub fn read_timeout ( mut self , timeout : impl Into < Option < Duration > > ) -> Self {
154
+ self . read_timeout = timeout. into ( ) ;
155
+ self
156
+ }
157
+
142
158
/// Set a time limit for how long a request should be retried. The default
143
159
/// is that there isn't a limit, meaning requests are retried forever.
144
160
///
@@ -182,12 +198,14 @@ mod tests {
182
198
. force_auth ( )
183
199
. max_retry_time ( Duration :: from_secs ( 32 ) )
184
200
. retry_limit ( 4 )
185
- . timeout ( Duration :: from_secs ( 600 ) ) ;
201
+ . timeout ( Duration :: from_secs ( 600 ) )
202
+ . read_timeout ( Duration :: from_secs ( 10 ) ) ;
186
203
187
204
assert ! ( cfg. force_auth) ;
188
205
assert_eq ! ( cfg. retry_limit, Some ( 4 ) ) ;
189
206
assert_eq ! ( cfg. max_retry_time, Some ( Duration :: from_secs( 32 ) ) ) ;
190
- assert_eq ! ( cfg. timeout, Duration :: from_secs( 600 ) ) ;
207
+ assert_eq ! ( cfg. timeout, Some ( Duration :: from_secs( 600 ) ) ) ;
208
+ assert_eq ! ( cfg. read_timeout, Some ( Duration :: from_secs( 10 ) ) ) ;
191
209
}
192
210
193
211
#[ test]
0 commit comments