@@ -7,6 +7,7 @@ use crate::{
77 stream:: { Stream , ThreadReceive , ThreadSend } ,
88 uri:: Uri ,
99} ;
10+ #[ cfg( feature = "auth" ) ]
1011use base64:: prelude:: * ;
1112use std:: {
1213 convert:: TryFrom ,
@@ -17,6 +18,7 @@ use std::{
1718 thread,
1819 time:: { Duration , Instant } ,
1920} ;
21+ #[ cfg( feature = "auth" ) ]
2022use zeroize:: { Zeroize , ZeroizeOnDrop , Zeroizing } ;
2123
2224const CR_LF : & str = "\r \n " ;
@@ -109,9 +111,11 @@ impl fmt::Display for HttpVersion {
109111/// Authentication details:
110112/// - Basic: username and password
111113/// - Bearer: token
114+ #[ cfg( feature = "auth" ) ]
112115#[ derive( Debug , PartialEq , Zeroize , ZeroizeOnDrop ) ]
113116pub struct Authentication ( AuthenticationType ) ;
114117
118+ #[ cfg( feature = "auth" ) ]
115119impl Authentication {
116120 /// Creates a new `Authentication` of type `Basic`.
117121 ///
@@ -172,11 +176,13 @@ impl Authentication {
172176
173177/// Authentication types
174178#[ derive( Debug , PartialEq , Zeroize , ZeroizeOnDrop ) ]
179+ #[ cfg( feature = "auth" ) ]
175180enum AuthenticationType {
176181 Basic { username : String , password : String } ,
177182 Bearer ( String ) ,
178183}
179184
185+ #[ cfg( feature = "auth" ) ]
180186impl AuthenticationType {
181187 /// Returns the authentication scheme as a string.
182188 const fn scheme ( & self ) -> & str {
@@ -409,6 +415,7 @@ impl<'a> RequestMessage<'a> {
409415 /// let request_msg = RequestMessage::new(&addr)
410416 /// .authentication(Authentication::bearer("secret456token123"));
411417 /// ```
418+ #[ cfg( feature = "auth" ) ]
412419 pub fn authentication < T > ( & mut self , auth : T ) -> & mut Self
413420 where
414421 Authentication : From < T > ,
@@ -629,6 +636,7 @@ impl<'a> Request<'a> {
629636 /// let request = Request::new(&addr)
630637 /// .authentication(Authentication::bearer("secret456token123"));
631638 /// ```
639+ #[ cfg( feature = "auth" ) ]
632640 pub fn authentication < T > ( & mut self , auth : T ) -> & mut Self
633641 where
634642 Authentication : From < T > ,
@@ -968,6 +976,7 @@ mod tests {
968976 }
969977
970978 #[ test]
979+ #[ cfg( feature = "auth" ) ]
971980 fn authentication_basic ( ) {
972981 let auth = Authentication :: basic ( "user" , "password123" ) ;
973982 assert_eq ! (
@@ -980,6 +989,7 @@ mod tests {
980989 }
981990
982991 #[ test]
992+ #[ cfg( feature = "auth" ) ]
983993 fn authentication_baerer ( ) {
984994 let auth = Authentication :: bearer ( "456secret123token" ) ;
985995 assert_eq ! (
@@ -989,6 +999,7 @@ mod tests {
989999 }
9901000
9911001 #[ test]
1002+ #[ cfg( feature = "auth" ) ]
9921003 fn authentication_header ( ) {
9931004 {
9941005 let auth = Authentication :: basic ( "user" , "password123" ) ;
@@ -1052,6 +1063,7 @@ mod tests {
10521063 }
10531064
10541065 #[ test]
1066+ #[ cfg( feature = "auth" ) ]
10551067 fn request_m_authentication ( ) {
10561068 let uri = Uri :: try_from ( URI ) . unwrap ( ) ;
10571069 let mut req = RequestMessage :: new ( & uri) ;
0 commit comments