@@ -49,8 +49,9 @@ pub struct ClientBuilder<E = &'static str, U = &'static str, P = &'static str> {
4949 endpoint : E ,
5050 username : U ,
5151 password : P ,
52- client : HttpClient ,
52+ client : Option < HttpClient > ,
5353 retry_settings : RetrySettings ,
54+ request_timeout : Option < Duration > ,
5455}
5556
5657impl Default for ClientBuilder {
@@ -68,13 +69,13 @@ impl ClientBuilder {
6869 /// Note that the default credentials are [limited to local connections](https://www.rabbitmq.com/docs/access-control)
6970 /// for security reasons.
7071 pub fn new ( ) -> Self {
71- let client = HttpClient :: new ( ) ;
7272 Self {
7373 endpoint : "http://localhost:15672/api" ,
7474 username : "guest" ,
7575 password : "guest" ,
76- client,
76+ client : None ,
7777 retry_settings : RetrySettings :: default ( ) ,
78+ request_timeout : None ,
7879 }
7980 }
8081}
@@ -105,6 +106,7 @@ where
105106 password,
106107 client : self . client ,
107108 retry_settings : self . retry_settings ,
109+ request_timeout : self . request_timeout ,
108110 }
109111 }
110112
@@ -122,14 +124,48 @@ where
122124 password : self . password ,
123125 client : self . client ,
124126 retry_settings : self . retry_settings ,
127+ request_timeout : self . request_timeout ,
125128 }
126129 }
127130
128131 /// Sets a custom HTTP client.
129132 ///
130133 /// Use a custom HTTP client to configure custom timeouts, proxy settings, TLS configuration.
134+ ///
135+ /// Note: If you provide a custom client, the timeout set via [`with_request_timeout`]
136+ /// will be ignored. Configure timeouts directly on your custom client instead.
131137 pub fn with_client ( self , client : HttpClient ) -> Self {
132- ClientBuilder { client, ..self }
138+ ClientBuilder {
139+ client : Some ( client) ,
140+ ..self
141+ }
142+ }
143+
144+ /// Sets the request timeout for HTTP operations.
145+ ///
146+ /// This timeout applies to the entire request/response cycle, including connection establishment,
147+ /// request transmission, and response receipt. If a request takes longer than this duration,
148+ /// it will be aborted and return a timeout error.
149+ ///
150+ /// **Important**: this setting is ignored if a custom HTTP client is used via [`with_client`].
151+ /// In that case, configure the timeout on the custom client instead.
152+ ///
153+ /// # Example
154+ /// ```rust
155+ /// use std::time::Duration;
156+ /// use rabbitmq_http_client::blocking_api::ClientBuilder;
157+ ///
158+ /// let client = ClientBuilder::new()
159+ /// .with_endpoint("http://localhost:15672/api")
160+ /// .with_basic_auth_credentials("user", "password")
161+ /// .with_request_timeout(Duration::from_secs(30))
162+ /// .build();
163+ /// ```
164+ pub fn with_request_timeout ( self , timeout : Duration ) -> Self {
165+ ClientBuilder {
166+ request_timeout : Some ( timeout) ,
167+ ..self
168+ }
133169 }
134170
135171 /// Sets retry settings for HTTP requests. See [`RetrySettings`].
@@ -146,8 +182,19 @@ where
146182 ///
147183 /// This consumes the `ClientBuilder`.
148184 pub fn build ( self ) -> Client < E , U , P > {
185+ let client = match self . client {
186+ Some ( c) => c,
187+ None => {
188+ let mut builder = HttpClient :: builder ( ) ;
189+ if let Some ( timeout) = self . request_timeout {
190+ builder = builder. timeout ( timeout) ;
191+ }
192+ builder. build ( ) . unwrap ( )
193+ }
194+ } ;
195+
149196 Client :: from_http_client_with_retry (
150- self . client ,
197+ client,
151198 self . endpoint ,
152199 self . username ,
153200 self . password ,
0 commit comments