@@ -58,6 +58,7 @@ pub struct ClientBuilder<E = &'static str, U = &'static str, P = &'static str> {
5858 password : P ,
5959 client : Option < HttpClient > ,
6060 retry_settings : RetrySettings ,
61+ connect_timeout : Option < Duration > ,
6162 request_timeout : Option < Duration > ,
6263}
6364
@@ -82,6 +83,7 @@ impl ClientBuilder {
8283 password : "guest" ,
8384 client : None ,
8485 retry_settings : RetrySettings :: default ( ) ,
86+ connect_timeout : None ,
8587 request_timeout : None ,
8688 }
8789 }
@@ -122,6 +124,7 @@ where
122124 password,
123125 client : self . client ,
124126 retry_settings : self . retry_settings ,
127+ connect_timeout : self . connect_timeout ,
125128 request_timeout : self . request_timeout ,
126129 }
127130 }
@@ -140,6 +143,7 @@ where
140143 password : self . password ,
141144 client : self . client ,
142145 retry_settings : self . retry_settings ,
146+ connect_timeout : self . connect_timeout ,
143147 request_timeout : self . request_timeout ,
144148 }
145149 }
@@ -148,7 +152,7 @@ where
148152 ///
149153 /// Use a custom HTTP client to configure custom timeouts, proxy settings, TLS configuration.
150154 ///
151- /// Note: If you provide a custom client, the timeout set via [`with_request_timeout`]
155+ /// Note: If you provide a custom client, timeouts set via builder methods
152156 /// will be ignored. Configure timeouts directly on your custom client instead.
153157 pub fn with_client ( self , client : HttpClient ) -> Self {
154158 ClientBuilder {
@@ -157,6 +161,21 @@ where
157161 }
158162 }
159163
164+ /// Sets the TCP connection timeout.
165+ ///
166+ /// This timeout applies only to the connection establishment phase (TCP + TLS handshake),
167+ /// not to the overall request. Useful for failing fast on unreachable hosts without
168+ /// cutting off slow-but-valid responses.
169+ ///
170+ /// **Important**: this setting is ignored if a custom HTTP client is used via [`with_client`].
171+ /// In that case, configure the timeout on the custom client instead.
172+ pub fn with_connect_timeout ( self , timeout : Duration ) -> Self {
173+ ClientBuilder {
174+ connect_timeout : Some ( timeout) ,
175+ ..self
176+ }
177+ }
178+
160179 /// Sets the request timeout for HTTP operations.
161180 ///
162181 /// This timeout applies to the entire request/response cycle, including connection establishment,
@@ -202,6 +221,9 @@ where
202221 Some ( c) => c,
203222 None => {
204223 let mut builder = HttpClient :: builder ( ) ;
224+ if let Some ( timeout) = self . connect_timeout {
225+ builder = builder. connect_timeout ( timeout) ;
226+ }
205227 if let Some ( timeout) = self . request_timeout {
206228 builder = builder. timeout ( timeout) ;
207229 }
0 commit comments