1- use std:: fmt:: Debug ;
21use std:: net:: SocketAddr ;
32use std:: pin:: Pin ;
43
@@ -18,7 +17,8 @@ cfg_if::cfg_if! {
1817
1918use crate :: { Config , Error } ;
2019
21- #[ derive( Clone , Debug ) ]
20+ #[ derive( Clone ) ]
21+ #[ cfg_attr( not( feature = "rustls" ) , derive( std:: fmt:: Debug ) ) ]
2222pub ( crate ) struct TlsConnection {
2323 host : String ,
2424 addr : SocketAddr ,
@@ -76,7 +76,7 @@ impl Manager<TlsStream<TcpStream>, Error> for TlsConnection {
7676 #[ cfg( feature = "unstable-config" ) ]
7777 raw_stream. set_nodelay ( self . config . tcp_no_delay ) ?;
7878
79- let tls_stream = add_tls ( & self . host , raw_stream) . await ?;
79+ let tls_stream = add_tls ( & self . host , raw_stream, & self . config ) . await ?;
8080 Ok ( tls_stream)
8181 }
8282
@@ -105,16 +105,36 @@ impl Manager<TlsStream<TcpStream>, Error> for TlsConnection {
105105
106106cfg_if:: cfg_if! {
107107 if #[ cfg( feature = "rustls" ) ] {
108- pub ( crate ) async fn add_tls( host: & str , stream: TcpStream ) -> Result <TlsStream <TcpStream >, std:: io:: Error > {
108+ #[ allow( unused_variables) ]
109+ pub ( crate ) async fn add_tls( host: & str , stream: TcpStream , config: & Config ) -> Result <TlsStream <TcpStream >, std:: io:: Error > {
110+ #[ cfg( all( feature = "h1_client" , feature = "unstable-config" ) ) ]
111+ let connector = if let Some ( ref tls_config) = config. tls_config {
112+ tls_config. clone( ) . into( )
113+ } else {
114+ async_tls:: TlsConnector :: default ( )
115+ } ;
116+ #[ cfg( not( feature = "unstable-config" ) ) ]
109117 let connector = async_tls:: TlsConnector :: default ( ) ;
118+
110119 connector. connect( host, stream) . await
111120 }
112121 } else if #[ cfg( feature = "native-tls" ) ] {
122+ #[ allow( unused_variables) ]
113123 pub ( crate ) async fn add_tls(
114124 host: & str ,
115125 stream: TcpStream ,
126+ config: & Config ,
116127 ) -> Result <TlsStream <TcpStream >, async_native_tls:: Error > {
117- async_native_tls:: connect( host, stream) . await
128+ #[ cfg( feature = "unstable-config" ) ]
129+ let connector = if let Some ( ref tls_config) = config. tls_config {
130+ tls_config. clone( ) . into( )
131+ } else {
132+ async_native_tls:: TlsConnector :: new( )
133+ } ;
134+ #[ cfg( not( feature = "unstable-config" ) ) ]
135+ let connector = async_native_tls:: TlsConnector :: new( ) ;
136+
137+ connector. connect( host, stream) . await
118138 }
119139 }
120140}
0 commit comments