@@ -35,6 +35,12 @@ pub struct Builder {
3535
3636 /// The additional headers to use for requests.
3737 headers : reqwest:: header:: HeaderMap ,
38+
39+ /// The connect timeout for the client.
40+ connect_timeout : Option < Duration > ,
41+
42+ /// The read timeout for the client.
43+ read_timeout : Option < Duration > ,
3844}
3945
4046impl Builder {
@@ -102,14 +108,33 @@ impl Builder {
102108 self
103109 }
104110
111+ /// Sets the connect timeout for the client.
112+ ///
113+ /// Defaults to 60 seconds.
114+ pub fn connect_timeout ( mut self , timeout : Duration ) -> Self {
115+ self . connect_timeout = Some ( timeout) ;
116+ self
117+ }
118+
119+ /// Sets the read timeout for the client.
120+ ///
121+ /// Defaults to 60 seconds.
122+ pub fn read_timeout ( mut self , timeout : Duration ) -> Self {
123+ self . read_timeout = Some ( timeout) ;
124+ self
125+ }
126+
105127 /// Consumes `self` and attempts to build a [`Client`] from the provided
106128 /// values.
107129 pub fn try_build ( self ) -> Result < Client > {
108130 let url = self . url . map ( Ok ) . unwrap_or ( Err ( Error :: Missing ( "url" ) ) ) ?;
109131
110132 let client = reqwest:: ClientBuilder :: new ( )
111- . connect_timeout ( Self :: DEFAULT_CONNECT_TIMEOUT )
112- . read_timeout ( Self :: DEFAULT_READ_TIMEOUT )
133+ . connect_timeout (
134+ self . connect_timeout
135+ . unwrap_or ( Self :: DEFAULT_CONNECT_TIMEOUT ) ,
136+ )
137+ . read_timeout ( self . read_timeout . unwrap_or ( Self :: DEFAULT_READ_TIMEOUT ) )
113138 . default_headers ( self . headers )
114139 . build ( ) ?;
115140
0 commit comments