@@ -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,52 @@ 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`. 
30- /// 
31- /// Takes number of DNS worker threads. 
3233pub  fn  new ( )  -> Self  { 
3334        let  mut  http = HttpConnector :: new ( ) ; 
35+ 
3436        http. enforce_http ( false ) ; 
37+ 
38+         ( http,  Self :: default_client_config ( ) ) . into ( ) 
39+     } 
40+ 
41+     /// Constructs default `ClientConfig` which later can be used for 
42+ /// construction of `HttpsConnector` with custom `HttpConnector`. 
43+ pub  fn  default_client_config ( )  -> ClientConfig  { 
3544        let  mut  config = ClientConfig :: new ( ) ; 
3645        config. alpn_protocols  = vec ! [ b"h2" . to_vec( ) ,  b"http/1.1" . to_vec( ) ] ; 
37-         #[ cfg( feature = "rustls-native-certs" ) ]    
46+         #[ cfg( feature = "rustls-native-certs" ) ]  
3847        { 
3948            config. root_store  = match  rustls_native_certs:: load_native_certs ( )  { 
4049                Ok ( store)  => store, 
4150                Err ( ( Some ( store) ,  err) )  => { 
4251                    warn ! ( "Could not load all certificates: {:?}" ,  err) ; 
4352                    store
4453                } 
45-                 Err ( ( None ,  err) )  => { 
46-                     Err ( err) . expect ( "cannot access native cert store" ) 
47-                 } 
54+                 Err ( ( None ,  err) )  => Err ( err) . expect ( "cannot access native cert store" ) , 
4855            } ; 
4956        } 
50-         #[ cfg( feature = "webpki-roots" ) ]    
57+         #[ cfg( feature = "webpki-roots" ) ]  
5158        { 
5259            config
5360                . root_store 
5461                . add_server_trust_anchors ( & webpki_roots:: TLS_SERVER_ROOTS ) ; 
5562        } 
5663        config. ct_logs  = Some ( & ct_logs:: LOGS ) ; 
57-         ( http,  config) . into ( ) 
64+ 
65+         config
5866    } 
5967} 
6068
61- #[ cfg( all( any( feature = "rustls-native-certs" ,  feature = "webpki-roots" ) ,  feature = "tokio-runtime" ) ) ]  
69+ #[ cfg( all(  
70+     any( feature = "rustls-native-certs" ,  feature = "webpki-roots" ) ,  
71+     feature = "tokio-runtime"  
72+ ) ) ] 
6273impl  Default  for  HttpsConnector < HttpConnector >  { 
6374    fn  default ( )  -> Self  { 
6475        Self :: new ( ) 
@@ -73,7 +84,7 @@ impl<T> fmt::Debug for HttpsConnector<T> {
7384
7485impl < H ,  C >  From < ( H ,  C ) >  for  HttpsConnector < H > 
7586where 
76-     C :  Into < Arc < ClientConfig > >   
87+     C :  Into < Arc < ClientConfig > > , 
7788{ 
7889    fn  from ( ( http,  cfg) :  ( H ,  C ) )  -> Self  { 
7990        HttpsConnector  { 
0 commit comments