@@ -2,6 +2,7 @@ use futures_util::FutureExt;
22#[ cfg( feature = "tokio-runtime" ) ]  
33use  hyper:: client:: connect:: HttpConnector ; 
44use  hyper:: { client:: connect:: Connection ,  service:: Service ,  Uri } ; 
5+ use  log:: warn; 
56use  rustls:: ClientConfig ; 
67use  std:: future:: Future ; 
78use  std:: pin:: Pin ; 
@@ -11,7 +12,6 @@ use std::{fmt, io};
1112use  tokio:: io:: { AsyncRead ,  AsyncWrite } ; 
1213use  tokio_rustls:: TlsConnector ; 
1314use  webpki:: DNSNameRef ; 
14- use  log:: warn; 
1515
1616use  crate :: stream:: MaybeHttpsStream ; 
1717
@@ -24,41 +24,27 @@ pub struct HttpsConnector<T> {
2424    tls_config :  Arc < ClientConfig > , 
2525} 
2626
27- #[ cfg( all( any( feature = "rustls-native-certs" ,  feature = "webpki-roots" ) ,  feature = "tokio-runtime" ) ) ]  
27+ #[ cfg( all(  
28+     any( feature = "rustls-native-certs" ,  feature = "webpki-roots" ) ,  
29+     feature = "tokio-runtime"  
30+ ) ) ] 
2831impl  HttpsConnector < HttpConnector >  { 
2932    /// Construct a new `HttpsConnector`. 
3033/// 
3134/// Takes number of DNS worker threads. 
3235pub  fn  new ( )  -> Self  { 
3336        let  mut  http = HttpConnector :: new ( ) ; 
37+ 
3438        http. enforce_http ( false ) ; 
35-         let  mut  config = ClientConfig :: new ( ) ; 
36-         config. alpn_protocols  = vec ! [ b"h2" . to_vec( ) ,  b"http/1.1" . to_vec( ) ] ; 
37-         #[ cfg( feature = "rustls-native-certs" ) ]   
38-         { 
39-             config. root_store  = match  rustls_native_certs:: load_native_certs ( )  { 
40-                 Ok ( store)  => store, 
41-                 Err ( ( Some ( store) ,  err) )  => { 
42-                     warn ! ( "Could not load all certificates: {:?}" ,  err) ; 
43-                     store
44-                 } 
45-                 Err ( ( None ,  err) )  => { 
46-                     Err ( err) . expect ( "cannot access native cert store" ) 
47-                 } 
48-             } ; 
49-         } 
50-         #[ cfg( feature = "webpki-roots" ) ]   
51-         { 
52-             config
53-                 . root_store 
54-                 . add_server_trust_anchors ( & webpki_roots:: TLS_SERVER_ROOTS ) ; 
55-         } 
56-         config. ct_logs  = Some ( & ct_logs:: LOGS ) ; 
57-         ( http,  config) . into ( ) 
39+ 
40+         http. into ( ) 
5841    } 
5942} 
6043
61- #[ cfg( all( any( feature = "rustls-native-certs" ,  feature = "webpki-roots" ) ,  feature = "tokio-runtime" ) ) ]  
44+ #[ cfg( all(  
45+     any( feature = "rustls-native-certs" ,  feature = "webpki-roots" ) ,  
46+     feature = "tokio-runtime"  
47+ ) ) ] 
6248impl  Default  for  HttpsConnector < HttpConnector >  { 
6349    fn  default ( )  -> Self  { 
6450        Self :: new ( ) 
@@ -73,7 +59,7 @@ impl<T> fmt::Debug for HttpsConnector<T> {
7359
7460impl < H ,  C >  From < ( H ,  C ) >  for  HttpsConnector < H > 
7561where 
76-     C :  Into < Arc < ClientConfig > >   
62+     C :  Into < Arc < ClientConfig > > , 
7763{ 
7864    fn  from ( ( http,  cfg) :  ( H ,  C ) )  -> Self  { 
7965        HttpsConnector  { 
8369    } 
8470} 
8571
72+ #[ cfg( all(  
73+     any( feature = "rustls-native-certs" ,  feature = "webpki-roots" ) ,  
74+     feature = "tokio-runtime"  
75+ ) ) ] 
76+ impl < H >  From < H >  for  HttpsConnector < H >  { 
77+     fn  from ( http :  H )  -> Self  { 
78+         let  mut  config = ClientConfig :: new ( ) ; 
79+         config. alpn_protocols  = vec ! [ b"h2" . to_vec( ) ,  b"http/1.1" . to_vec( ) ] ; 
80+         #[ cfg( feature = "rustls-native-certs" ) ]  
81+         { 
82+             config. root_store  = match  rustls_native_certs:: load_native_certs ( )  { 
83+                 Ok ( store)  => store, 
84+                 Err ( ( Some ( store) ,  err) )  => { 
85+                     warn ! ( "Could not load all certificates: {:?}" ,  err) ; 
86+                     store
87+                 } 
88+                 Err ( ( None ,  err) )  => Err ( err) . expect ( "cannot access native cert store" ) , 
89+             } ; 
90+         } 
91+         #[ cfg( feature = "webpki-roots" ) ]  
92+         { 
93+             config
94+                 . root_store 
95+                 . add_server_trust_anchors ( & webpki_roots:: TLS_SERVER_ROOTS ) ; 
96+         } 
97+         config. ct_logs  = Some ( & ct_logs:: LOGS ) ; 
98+ 
99+         HttpsConnector  { 
100+             http, 
101+             tls_config :  config. into ( ) , 
102+         } 
103+     } 
104+ } 
105+ 
86106impl < T >  Service < Uri >  for  HttpsConnector < T > 
87107where 
88108    T :  Service < Uri > , 
0 commit comments