@@ -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 {
@@ -380,6 +385,8 @@ impl ClientBuilder {
380
385
#[ cfg( feature = "http3" ) ]
381
386
h3_send_grease : None ,
382
387
dns_resolver : None ,
388
+ #[ cfg( unix) ]
389
+ unix_socket : None ,
383
390
} ,
384
391
}
385
392
}
@@ -909,6 +916,12 @@ impl ClientBuilder {
909
916
#[ cfg( feature = "socks" ) ]
910
917
connector_builder. set_socks_resolver ( resolver) ;
911
918
919
+ // TODO: It'd be best to refactor this so the HttpConnector is never
920
+ // constructed at all. But there's a lot of code for all the different
921
+ // ways TLS can be configured...
922
+ #[ cfg( unix) ]
923
+ connector_builder. set_unix_socket ( config. unix_socket ) ;
924
+
912
925
let mut builder =
913
926
hyper_util:: client:: legacy:: Client :: builder ( hyper_util:: rt:: TokioExecutor :: new ( ) ) ;
914
927
#[ cfg( feature = "http2" ) ]
@@ -1712,6 +1725,25 @@ impl ClientBuilder {
1712
1725
self
1713
1726
}
1714
1727
1728
+ // Alt Transports
1729
+
1730
+ /// Set that all connections will use this Unix socket.
1731
+ ///
1732
+ /// If a request URI uses the `https` scheme, TLS will still be used over
1733
+ /// the Unix socket.
1734
+ ///
1735
+ /// # Note
1736
+ ///
1737
+ /// This option is not compatible with any of the TCP or Proxy options.
1738
+ /// Setting this will ignore all those options previously set.
1739
+ ///
1740
+ /// Likewise, DNS resolution will not be done on the domain name.
1741
+ #[ cfg( unix) ]
1742
+ pub fn unix_socket ( mut self , path : impl UnixSocketProvider ) -> ClientBuilder {
1743
+ self . config . unix_socket = Some ( path. reqwest_uds_path ( crate :: connect:: uds:: Internal ) . into ( ) ) ;
1744
+ self
1745
+ }
1746
+
1715
1747
// TLS options
1716
1748
1717
1749
/// Add a custom root certificate.
@@ -2754,6 +2786,11 @@ impl Config {
2754
2786
f. field ( "tls_enable_early_data" , & true ) ;
2755
2787
}
2756
2788
}
2789
+
2790
+ #[ cfg( unix) ]
2791
+ if let Some ( ref p) = self . unix_socket {
2792
+ f. field ( "unix_socket" , p) ;
2793
+ }
2757
2794
}
2758
2795
}
2759
2796
0 commit comments