1
+ use std:: sync:: Arc ;
2
+
1
3
use hyper_util:: client:: legacy:: connect:: HttpConnector ;
2
4
#[ cfg( any( feature = "rustls-native-certs" , feature = "webpki-roots" ) ) ]
3
5
use rustls:: crypto:: CryptoProvider ;
@@ -35,20 +37,24 @@ impl ConnectorBuilder<WantsTlsConfig> {
35
37
Self ( WantsTlsConfig ( ( ) ) )
36
38
}
37
39
38
- /// Passes a rustls [`ClientConfig`] to configure the TLS connection
40
+ /// Passes a rustls [`ClientConfig`] to configure the TLS connection.
39
41
///
40
42
/// The [`alpn_protocols`](ClientConfig::alpn_protocols) field is
41
43
/// required to be empty (or the function will panic) and will be
42
44
/// rewritten to match the enabled schemes (see
43
45
/// [`enable_http1`](ConnectorBuilder::enable_http1),
44
46
/// [`enable_http2`](ConnectorBuilder::enable_http2)) before the
45
47
/// 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 ( ) ;
47
53
assert ! (
48
- config . alpn_protocols. is_empty( ) ,
54
+ tls_config . alpn_protocols. is_empty( ) ,
49
55
"ALPN protocols should not be pre-defined"
50
56
) ;
51
- ConnectorBuilder ( WantsSchemes { tls_config : config } )
57
+ ConnectorBuilder ( WantsSchemes { tls_config } )
52
58
}
53
59
54
60
/// Use rustls' default crypto provider and other defaults, and the platform verifier
@@ -133,7 +139,7 @@ impl Default for ConnectorBuilder<WantsTlsConfig> {
133
139
/// State of a builder that needs schemes (https:// and http://) to be
134
140
/// configured next
135
141
pub struct WantsSchemes {
136
- tls_config : ClientConfig ,
142
+ tls_config : Arc < ClientConfig > ,
137
143
}
138
144
139
145
impl ConnectorBuilder < WantsSchemes > {
@@ -166,7 +172,7 @@ impl ConnectorBuilder<WantsSchemes> {
166
172
///
167
173
/// No protocol has been enabled at this point.
168
174
pub struct WantsProtocols1 {
169
- tls_config : ClientConfig ,
175
+ tls_config : Arc < ClientConfig > ,
170
176
https_only : bool ,
171
177
override_server_name : Option < String > ,
172
178
}
@@ -176,7 +182,7 @@ impl WantsProtocols1 {
176
182
HttpsConnector {
177
183
force_https : self . https_only ,
178
184
http : conn,
179
- tls_config : std :: sync :: Arc :: new ( self . tls_config ) ,
185
+ tls_config : self . tls_config ,
180
186
override_server_name : self . override_server_name ,
181
187
}
182
188
}
@@ -203,7 +209,7 @@ impl ConnectorBuilder<WantsProtocols1> {
203
209
/// This needs to be called explicitly, no protocol is enabled by default
204
210
#[ cfg( feature = "http2" ) ]
205
211
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( ) ] ;
207
213
ConnectorBuilder ( WantsProtocols3 {
208
214
inner : self . 0 ,
209
215
enable_http1 : false ,
@@ -221,7 +227,7 @@ impl ConnectorBuilder<WantsProtocols1> {
221
227
#[ cfg( not( feature = "http1" ) ) ]
222
228
let alpn_protocols = vec ! [ b"h2" . to_vec( ) ] ;
223
229
224
- self . 0 . tls_config . alpn_protocols = alpn_protocols;
230
+ Arc :: make_mut ( & mut self . 0 . tls_config ) . alpn_protocols = alpn_protocols;
225
231
ConnectorBuilder ( WantsProtocols3 {
226
232
inner : self . 0 ,
227
233
enable_http1 : cfg ! ( feature = "http1" ) ,
@@ -259,7 +265,8 @@ impl ConnectorBuilder<WantsProtocols2> {
259
265
/// This needs to be called explicitly, no protocol is enabled by default
260
266
#[ cfg( feature = "http2" ) ]
261
267
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( ) ] ;
263
270
ConnectorBuilder ( WantsProtocols3 {
264
271
inner : self . 0 . inner ,
265
272
enable_http1 : true ,
0 commit comments