@@ -20,6 +20,8 @@ use crate::async_impl::h3_client::connect::{H3ClientConfig, H3Connector};
20
20
#[ cfg( feature = "http3" ) ]
21
21
use crate :: async_impl:: h3_client:: H3Client ;
22
22
use crate :: config:: { RequestConfig , RequestTimeout } ;
23
+ #[ cfg( unix) ]
24
+ use crate :: connect:: uds:: UnixSocketProvider ;
23
25
use crate :: connect:: {
24
26
sealed:: { Conn , Unnameable } ,
25
27
BoxedConnectorLayer , BoxedConnectorService , Connector , ConnectorBuilder ,
@@ -256,6 +258,9 @@ struct Config {
256
258
h3_send_grease : Option < bool > ,
257
259
dns_overrides : HashMap < String , Vec < SocketAddr > > ,
258
260
dns_resolver : Option < Arc < dyn Resolve > > ,
261
+
262
+ #[ cfg( unix) ]
263
+ unix_socket : Option < Arc < std:: path:: Path > > ,
259
264
}
260
265
261
266
impl Default for ClientBuilder {
@@ -378,6 +383,8 @@ impl ClientBuilder {
378
383
#[ cfg( feature = "http3" ) ]
379
384
h3_send_grease : None ,
380
385
dns_resolver : None ,
386
+ #[ cfg( unix) ]
387
+ unix_socket : None ,
381
388
} ,
382
389
}
383
390
}
@@ -907,6 +914,12 @@ impl ClientBuilder {
907
914
#[ cfg( feature = "socks" ) ]
908
915
connector_builder. set_socks_resolver ( resolver) ;
909
916
917
+ // TODO: It'd be best to refactor this so the HttpConnector is never
918
+ // constructed at all. But there's a lot of code for all the different
919
+ // ways TLS can be configured...
920
+ #[ cfg( unix) ]
921
+ connector_builder. set_unix_socket ( config. unix_socket ) ;
922
+
910
923
let mut builder =
911
924
hyper_util:: client:: legacy:: Client :: builder ( hyper_util:: rt:: TokioExecutor :: new ( ) ) ;
912
925
#[ cfg( feature = "http2" ) ]
@@ -1710,6 +1723,25 @@ impl ClientBuilder {
1710
1723
self
1711
1724
}
1712
1725
1726
+ // Alt Transports
1727
+
1728
+ /// Set that all connections will use this Unix socket.
1729
+ ///
1730
+ /// If a request URI uses the `https` scheme, TLS will still be used over
1731
+ /// the Unix socket.
1732
+ ///
1733
+ /// # Note
1734
+ ///
1735
+ /// This option is not compatible with any of the TCP or Proxy options.
1736
+ /// Setting this will ignore all those options previously set.
1737
+ ///
1738
+ /// Likewise, DNS resolution will not be done on the domain name.
1739
+ #[ cfg( unix) ]
1740
+ pub fn unix_socket ( mut self , path : impl UnixSocketProvider ) -> ClientBuilder {
1741
+ self . config . unix_socket = Some ( path. reqwest_uds_path ( crate :: connect:: uds:: Internal ) . into ( ) ) ;
1742
+ self
1743
+ }
1744
+
1713
1745
// TLS options
1714
1746
1715
1747
/// Add a custom root certificate.
@@ -2752,6 +2784,11 @@ impl Config {
2752
2784
f. field ( "tls_enable_early_data" , & true ) ;
2753
2785
}
2754
2786
}
2787
+
2788
+ #[ cfg( unix) ]
2789
+ if let Some ( ref p) = self . unix_socket {
2790
+ f. field ( "unix_socket" , p) ;
2791
+ }
2755
2792
}
2756
2793
}
2757
2794
0 commit comments