@@ -29,14 +29,14 @@ use crate::{Error, Method, ResponseLazy};
2929
3030type UnsecuredStream = TcpStream ;
3131
32- #[ cfg( feature = "rustls" ) ]
32+ #[ cfg( any ( feature = "rustls" , feature = "native-tls" ) ) ]
3333mod rustls_stream;
34- #[ cfg( feature = "rustls" ) ]
34+ #[ cfg( any ( feature = "rustls" , feature = "native-tls" ) ) ]
3535type SecuredStream = rustls_stream:: SecuredStream ;
3636
3737pub ( crate ) enum HttpStream {
3838 Unsecured ( UnsecuredStream , Option < Instant > ) ,
39- #[ cfg( feature = "rustls" ) ]
39+ #[ cfg( any ( feature = "rustls" , feature = "native-tls" ) ) ]
4040 Secured ( Box < SecuredStream > , Option < Instant > ) ,
4141 #[ cfg( feature = "async" ) ]
4242 Buffer ( std:: io:: Cursor < Vec < u8 > > ) ,
@@ -81,7 +81,7 @@ impl Read for HttpStream {
8181 timeout ( inner, * timeout_at) ?;
8282 inner. read ( buf)
8383 }
84- #[ cfg( feature = "rustls" ) ]
84+ #[ cfg( any ( feature = "rustls" , feature = "native-tls" ) ) ]
8585 HttpStream :: Secured ( inner, timeout_at) => {
8686 timeout ( inner. get_ref ( ) , * timeout_at) ?;
8787 inner. read ( buf)
@@ -111,7 +111,7 @@ impl Write for HttpStream {
111111 set_socket_write_timeout ( inner, * timeout_at) ?;
112112 inner. write ( buf)
113113 }
114- #[ cfg( feature = "rustls" ) ]
114+ #[ cfg( any ( feature = "rustls" , feature = "native-tls" ) ) ]
115115 HttpStream :: Secured ( inner, timeout_at) => {
116116 set_socket_write_timeout ( inner. get_ref ( ) , * timeout_at) ?;
117117 inner. write ( buf)
@@ -137,7 +137,7 @@ impl Write for HttpStream {
137137 set_socket_write_timeout ( inner, * timeout_at) ?;
138138 inner. flush ( )
139139 }
140- #[ cfg( feature = "rustls" ) ]
140+ #[ cfg( any ( feature = "rustls" , feature = "native-tls" ) ) ]
141141 HttpStream :: Secured ( inner, timeout_at) => {
142142 set_socket_write_timeout ( inner. get_ref ( ) , * timeout_at) ?;
143143 inner. flush ( )
@@ -158,13 +158,13 @@ impl Write for HttpStream {
158158 }
159159}
160160
161- #[ cfg( feature = "tokio-rustls" ) ]
161+ #[ cfg( any ( feature = "tokio-rustls" , feature = "tokio-native-tls" ) ) ]
162162type AsyncSecuredStream = rustls_stream:: AsyncSecuredStream ;
163163
164164#[ cfg( feature = "async" ) ]
165165pub ( crate ) enum AsyncHttpStream {
166166 Unsecured ( AsyncTcpStream ) ,
167- #[ cfg( feature = "tokio-rustls" ) ]
167+ #[ cfg( any ( feature = "tokio-rustls" , feature = "tokio-native-tls" ) ) ]
168168 Secured ( Box < AsyncSecuredStream > ) ,
169169}
170170
@@ -177,7 +177,7 @@ impl AsyncRead for AsyncHttpStream {
177177 ) -> Poll < io:: Result < ( ) > > {
178178 match & mut * self {
179179 AsyncHttpStream :: Unsecured ( inner) => Pin :: new ( inner) . poll_read ( cx, buf) ,
180- #[ cfg( feature = "tokio-rustls" ) ]
180+ #[ cfg( any ( feature = "tokio-rustls" , feature = "tokio-native-tls" ) ) ]
181181 AsyncHttpStream :: Secured ( inner) => Pin :: new ( inner) . poll_read ( cx, buf) ,
182182 }
183183 }
@@ -192,23 +192,23 @@ impl AsyncWrite for AsyncHttpStream {
192192 ) -> Poll < io:: Result < usize > > {
193193 match & mut * self {
194194 AsyncHttpStream :: Unsecured ( inner) => Pin :: new ( inner) . poll_write ( cx, buf) ,
195- #[ cfg( feature = "tokio-rustls" ) ]
195+ #[ cfg( any ( feature = "tokio-rustls" , feature = "tokio-native-tls" ) ) ]
196196 AsyncHttpStream :: Secured ( inner) => Pin :: new ( inner) . poll_write ( cx, buf) ,
197197 }
198198 }
199199
200200 fn poll_flush ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
201201 match & mut * self {
202202 AsyncHttpStream :: Unsecured ( inner) => Pin :: new ( inner) . poll_flush ( cx) ,
203- #[ cfg( feature = "tokio-rustls" ) ]
203+ #[ cfg( any ( feature = "tokio-rustls" , feature = "tokio-native-tls" ) ) ]
204204 AsyncHttpStream :: Secured ( inner) => Pin :: new ( inner) . poll_flush ( cx) ,
205205 }
206206 }
207207
208208 fn poll_shutdown ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
209209 match & mut * self {
210210 AsyncHttpStream :: Unsecured ( inner) => Pin :: new ( inner) . poll_shutdown ( cx) ,
211- #[ cfg( feature = "tokio-rustls" ) ]
211+ #[ cfg( any ( feature = "tokio-rustls" , feature = "tokio-native-tls" ) ) ]
212212 AsyncHttpStream :: Secured ( inner) => Pin :: new ( inner) . poll_shutdown ( cx) ,
213213 }
214214 }
@@ -271,10 +271,8 @@ impl AsyncConnection {
271271 let socket = Self :: connect ( params) . await ?;
272272
273273 if params. https {
274- #[ cfg( not( feature = "tokio-rustls" ) ) ]
275- return Err ( Error :: HttpsFeatureNotEnabled ) ;
276- #[ cfg( feature = "tokio-rustls" ) ]
277- rustls_stream:: wrap_async_stream ( socket, params. host ) . await
274+ // temp call
275+ Self :: wrap_async_stream ( socket, params. host ) . await
278276 } else {
279277 Ok ( AsyncHttpStream :: Unsecured ( socket) )
280278 }
@@ -298,6 +296,23 @@ impl AsyncConnection {
298296 } ) ) ) )
299297 }
300298
299+ /// Temp Method implementation
300+ #[ cfg( any( feature = "tokio-rustls" , feature = "tokio-native-tls" ) ) ]
301+ async fn wrap_async_stream (
302+ socket : AsyncTcpStream ,
303+ host : & str ,
304+ ) -> Result < AsyncHttpStream , Error > {
305+ rustls_stream:: wrap_async_stream ( socket, host) . await
306+ }
307+
308+ /// Temp Method implementation
309+ #[ cfg( not( any( feature = "tokio-rustls" , feature = "tokio-native-tls" ) ) ) ]
310+ async fn wrap_async_stream (
311+ _socket : AsyncTcpStream ,
312+ _host : & str ,
313+ ) -> Result < AsyncHttpStream , Error > {
314+ Err ( Error :: HttpsFeatureNotEnabled )
315+ }
301316 async fn tcp_connect ( host : & str , port : u16 ) -> Result < AsyncTcpStream , Error > {
302317 #[ cfg( feature = "log" ) ]
303318 log:: trace!( "Looking up host {host}" ) ;
@@ -653,13 +668,10 @@ impl Connection {
653668 let socket = Self :: connect ( params, timeout_at) ?;
654669
655670 let stream = if params. https {
656- #[ cfg( not( feature = "rustls" ) ) ]
671+ #[ cfg( not( any ( feature = "rustls" , feature = "native-tls" ) ) ) ]
657672 return Err ( Error :: HttpsFeatureNotEnabled ) ;
658- #[ cfg( feature = "rustls" ) ]
659- {
660- let tls = rustls_stream:: wrap_stream ( socket, params. host ) ?;
661- HttpStream :: Secured ( Box :: new ( tls) , timeout_at)
662- }
673+ #[ cfg( any( feature = "rustls" , feature = "native-tls" ) ) ]
674+ rustls_stream:: wrap_stream ( socket, params. host ) ?
663675 } else {
664676 HttpStream :: create_unsecured ( socket, timeout_at)
665677 } ;
0 commit comments