1+ use std:: sync:: Arc ;
2+
13use hyper_util:: client:: legacy:: connect:: HttpConnector ;
24#[ cfg( any( feature = "rustls-native-certs" , feature = "webpki-roots" ) ) ]
35use rustls:: crypto:: CryptoProvider ;
@@ -35,20 +37,24 @@ impl ConnectorBuilder<WantsTlsConfig> {
3537 Self ( WantsTlsConfig ( ( ) ) )
3638 }
3739
38- /// Passes a rustls [`ClientConfig`] to configure the TLS connection
40+ /// Passes a rustls [`ClientConfig`] to configure the TLS connection.
3941 ///
4042 /// The [`alpn_protocols`](ClientConfig::alpn_protocols) field is
4143 /// required to be empty (or the function will panic) and will be
4244 /// rewritten to match the enabled schemes (see
4345 /// [`enable_http1`](ConnectorBuilder::enable_http1),
4446 /// [`enable_http2`](ConnectorBuilder::enable_http2)) before the
4547 /// connector is built.
46- pub fn with_tls_config ( self , config : ClientConfig ) -> ConnectorBuilder < WantsSchemes > {
48+ pub fn with_tls_config (
49+ self ,
50+ config : impl Into < Arc < ClientConfig > > ,
51+ ) -> ConnectorBuilder < WantsSchemes > {
52+ let tls_config = config. into ( ) ;
4753 assert ! (
48- config . alpn_protocols. is_empty( ) ,
54+ tls_config . alpn_protocols. is_empty( ) ,
4955 "ALPN protocols should not be pre-defined"
5056 ) ;
51- ConnectorBuilder ( WantsSchemes { tls_config : config } )
57+ ConnectorBuilder ( WantsSchemes { tls_config } )
5258 }
5359
5460 /// Use rustls' default crypto provider and other defaults, and the platform verifier
@@ -133,7 +139,7 @@ impl Default for ConnectorBuilder<WantsTlsConfig> {
133139/// State of a builder that needs schemes (https:// and http://) to be
134140/// configured next
135141pub struct WantsSchemes {
136- tls_config : ClientConfig ,
142+ tls_config : Arc < ClientConfig > ,
137143}
138144
139145impl ConnectorBuilder < WantsSchemes > {
@@ -166,7 +172,7 @@ impl ConnectorBuilder<WantsSchemes> {
166172///
167173/// No protocol has been enabled at this point.
168174pub struct WantsProtocols1 {
169- tls_config : ClientConfig ,
175+ tls_config : Arc < ClientConfig > ,
170176 https_only : bool ,
171177 override_server_name : Option < String > ,
172178}
@@ -176,7 +182,7 @@ impl WantsProtocols1 {
176182 HttpsConnector {
177183 force_https : self . https_only ,
178184 http : conn,
179- tls_config : std :: sync :: Arc :: new ( self . tls_config ) ,
185+ tls_config : self . tls_config ,
180186 override_server_name : self . override_server_name ,
181187 }
182188 }
@@ -203,7 +209,7 @@ impl ConnectorBuilder<WantsProtocols1> {
203209 /// This needs to be called explicitly, no protocol is enabled by default
204210 #[ cfg( feature = "http2" ) ]
205211 pub fn enable_http2 ( mut self ) -> ConnectorBuilder < WantsProtocols3 > {
206- self . 0 . tls_config . alpn_protocols = vec ! [ b"h2" . to_vec( ) ] ;
212+ Arc :: make_mut ( & mut self . 0 . tls_config ) . alpn_protocols = vec ! [ b"h2" . to_vec( ) ] ;
207213 ConnectorBuilder ( WantsProtocols3 {
208214 inner : self . 0 ,
209215 enable_http1 : false ,
@@ -221,7 +227,7 @@ impl ConnectorBuilder<WantsProtocols1> {
221227 #[ cfg( not( feature = "http1" ) ) ]
222228 let alpn_protocols = vec ! [ b"h2" . to_vec( ) ] ;
223229
224- self . 0 . tls_config . alpn_protocols = alpn_protocols;
230+ Arc :: make_mut ( & mut self . 0 . tls_config ) . alpn_protocols = alpn_protocols;
225231 ConnectorBuilder ( WantsProtocols3 {
226232 inner : self . 0 ,
227233 enable_http1 : cfg ! ( feature = "http1" ) ,
@@ -259,7 +265,8 @@ impl ConnectorBuilder<WantsProtocols2> {
259265 /// This needs to be called explicitly, no protocol is enabled by default
260266 #[ cfg( feature = "http2" ) ]
261267 pub fn enable_http2 ( mut self ) -> ConnectorBuilder < WantsProtocols3 > {
262- self . 0 . inner . tls_config . alpn_protocols = vec ! [ b"h2" . to_vec( ) , b"http/1.1" . to_vec( ) ] ;
268+ Arc :: make_mut ( & mut self . 0 . inner . tls_config ) . alpn_protocols =
269+ vec ! [ b"h2" . to_vec( ) , b"http/1.1" . to_vec( ) ] ;
263270 ConnectorBuilder ( WantsProtocols3 {
264271 inner : self . 0 . inner ,
265272 enable_http1 : true ,
0 commit comments