@@ -75,7 +75,9 @@ pub struct ClientBuilder {
75
75
url : Uri ,
76
76
headers : HeaderMap ,
77
77
reconnect_opts : ReconnectOptions ,
78
+ connect_timeout : Option < Duration > ,
78
79
read_timeout : Option < Duration > ,
80
+ write_timeout : Option < Duration > ,
79
81
last_event_id : Option < String > ,
80
82
method : String ,
81
83
body : Option < String > ,
@@ -97,7 +99,9 @@ impl ClientBuilder {
97
99
url,
98
100
headers : header_map,
99
101
reconnect_opts : ReconnectOptions :: default ( ) ,
102
+ connect_timeout : None ,
100
103
read_timeout : None ,
104
+ write_timeout : None ,
101
105
last_event_id : None ,
102
106
method : String :: from ( "GET" ) ,
103
107
max_redirects : None ,
@@ -144,12 +148,25 @@ impl ClientBuilder {
144
148
self . header ( "Authorization" , & value)
145
149
}
146
150
151
+ /// Set a connect timeout for the underlying connection. There is no connect timeout by
152
+ /// default.
153
+ pub fn connect_timeout ( mut self , connect_timeout : Duration ) -> ClientBuilder {
154
+ self . connect_timeout = Some ( connect_timeout) ;
155
+ self
156
+ }
157
+
147
158
/// Set a read timeout for the underlying connection. There is no read timeout by default.
148
159
pub fn read_timeout ( mut self , read_timeout : Duration ) -> ClientBuilder {
149
160
self . read_timeout = Some ( read_timeout) ;
150
161
self
151
162
}
152
163
164
+ /// Set a write timeout for the underlying connection. There is no write timeout by default.
165
+ pub fn write_timeout ( mut self , write_timeout : Duration ) -> ClientBuilder {
166
+ self . write_timeout = Some ( write_timeout) ;
167
+ self
168
+ }
169
+
153
170
/// Configure the client's reconnect behaviour according to the supplied
154
171
/// [`ReconnectOptions`].
155
172
///
@@ -176,7 +193,9 @@ impl ClientBuilder {
176
193
C :: Error : Into < BoxError > ,
177
194
{
178
195
let mut connector = TimeoutConnector :: new ( conn) ;
196
+ connector. set_connect_timeout ( self . connect_timeout ) ;
179
197
connector. set_read_timeout ( self . read_timeout ) ;
198
+ connector. set_write_timeout ( self . write_timeout ) ;
180
199
181
200
let client = hyper:: Client :: builder ( ) . build :: < _ , hyper:: Body > ( connector) ;
182
201
0 commit comments