@@ -9,6 +9,7 @@ use bytes::{Buf, Bytes};
99use http:: header:: { HeaderValue , CONNECTION } ;
1010use http:: { HeaderMap , Method , Version } ;
1111use httparse:: ParserConfig ;
12+ #[ cfg( feature = "tracing" ) ]
1213use tracing:: { debug, error, trace} ;
1314
1415use super :: io:: Buffered ;
@@ -197,6 +198,7 @@ where
197198 cx : & mut task:: Context < ' _ > ,
198199 ) -> Poll < Option < crate :: Result < ( MessageHead < T :: Incoming > , DecodedLength , Wants ) > > > {
199200 debug_assert ! ( self . can_read_head( ) ) ;
201+ #[ cfg( feature = "tracing" ) ]
200202 trace ! ( "Conn::read_head" ) ;
201203
202204 let msg = match ready ! ( self . io. parse:: <T >(
@@ -228,6 +230,7 @@ where
228230 // Note: don't deconstruct `msg` into local variables, it appears
229231 // the optimizer doesn't remove the extra copies.
230232
233+ #[ cfg( feature = "tracing" ) ]
231234 debug ! ( "incoming body is {}" , msg. decode) ;
232235
233236 // Prevent accepting HTTP/0.9 responses after the initial one, if any.
@@ -250,6 +253,7 @@ where
250253 } ;
251254
252255 if msg. decode == DecodedLength :: ZERO {
256+ #[ cfg( feature = "tracing" ) ]
253257 if msg. expect_continue {
254258 debug ! ( "ignoring expect-continue since body is empty" ) ;
255259 }
@@ -277,6 +281,7 @@ where
277281 let was_mid_parse = e. is_parse ( ) || !self . io . read_buf ( ) . is_empty ( ) ;
278282 if was_mid_parse || must_error {
279283 // We check if the buf contains the h2 Preface
284+ #[ cfg( feature = "tracing" ) ]
280285 debug ! (
281286 "parse error ({}) with {} bytes" ,
282287 e,
@@ -287,6 +292,7 @@ where
287292 Err ( e) => Poll :: Ready ( Some ( Err ( e) ) ) ,
288293 }
289294 } else {
295+ #[ cfg( feature = "tracing" ) ]
290296 debug ! ( "read eof" ) ;
291297 self . close_write ( ) ;
292298 Poll :: Ready ( None )
@@ -304,6 +310,7 @@ where
304310 match ready ! ( decoder. decode( cx, & mut self . io) ) {
305311 Ok ( slice) => {
306312 let ( reading, chunk) = if decoder. is_eof ( ) {
313+ #[ cfg( feature = "tracing" ) ]
307314 debug ! ( "incoming body completed" ) ;
308315 (
309316 Reading :: KeepAlive ,
@@ -314,6 +321,7 @@ where
314321 } ,
315322 )
316323 } else if slice. is_empty ( ) {
324+ #[ cfg( feature = "tracing" ) ]
317325 error ! ( "incoming body unexpectedly ended" ) ;
318326 // This should be unreachable, since all 3 decoders
319327 // either set eof=true or return an Err when reading
@@ -325,6 +333,7 @@ where
325333 ( reading, Poll :: Ready ( chunk) )
326334 }
327335 Err ( e) => {
336+ #[ cfg( feature = "tracing" ) ]
328337 debug ! ( "incoming body decode error: {}" , e) ;
329338 ( Reading :: Closed , Poll :: Ready ( Some ( Err ( e) ) ) )
330339 }
@@ -333,6 +342,7 @@ where
333342 Reading :: Continue ( ref decoder) => {
334343 // Write the 100 Continue if not already responded...
335344 if let Writing :: Init = self . state . writing {
345+ #[ cfg( feature = "tracing" ) ]
336346 trace ! ( "automatically sending 100 Continue" ) ;
337347 let cont = b"HTTP/1.1 100 Continue\r \n \r \n " ;
338348 self . io . headers_buf ( ) . extend_from_slice ( cont) ;
@@ -388,6 +398,7 @@ where
388398 debug_assert ! ( T :: is_client( ) ) ;
389399
390400 if !self . io . read_buf ( ) . is_empty ( ) {
401+ #[ cfg( feature = "tracing" ) ]
391402 debug ! ( "received an unexpected {} bytes" , self . io. read_buf( ) . len( ) ) ;
392403 return Poll :: Ready ( Err ( crate :: Error :: new_unexpected_message ( ) ) ) ;
393404 }
@@ -396,9 +407,11 @@ where
396407
397408 if num_read == 0 {
398409 let ret = if self . should_error_on_eof ( ) {
410+ #[ cfg( feature = "tracing" ) ]
399411 trace ! ( "found unexpected EOF on busy connection: {:?}" , self . state) ;
400412 Poll :: Ready ( Err ( crate :: Error :: new_incomplete ( ) ) )
401413 } else {
414+ #[ cfg( feature = "tracing" ) ]
402415 trace ! ( "found EOF on idle connection, closing" ) ;
403416 Poll :: Ready ( Ok ( ( ) ) )
404417 } ;
@@ -408,6 +421,7 @@ where
408421 return ret;
409422 }
410423
424+ #[ cfg( feature = "tracing" ) ]
411425 debug ! (
412426 "received unexpected {} bytes on an idle connection" ,
413427 num_read
@@ -426,6 +440,7 @@ where
426440 let num_read = ready ! ( self . force_io_read( cx) ) . map_err ( crate :: Error :: new_io) ?;
427441
428442 if num_read == 0 {
443+ #[ cfg( feature = "tracing" ) ]
429444 trace ! ( "found unexpected EOF on busy connection: {:?}" , self . state) ;
430445 self . state . close_read ( ) ;
431446 Poll :: Ready ( Err ( crate :: Error :: new_incomplete ( ) ) )
@@ -439,6 +454,7 @@ where
439454
440455 let result = ready ! ( self . io. poll_read_from_io( cx) ) ;
441456 Poll :: Ready ( result. map_err ( |e| {
457+ #[ cfg( feature = "tracing" ) ]
442458 trace ! ( "force_io_read; io error = {:?}" , e) ;
443459 self . state . close ( ) ;
444460 e
@@ -468,6 +484,7 @@ where
468484 match self . io . poll_read_from_io ( cx) {
469485 Poll :: Ready ( Ok ( n) ) => {
470486 if n == 0 {
487+ #[ cfg( feature = "tracing" ) ]
471488 trace ! ( "maybe_notify; read eof" ) ;
472489 if self . state . is_idle ( ) {
473490 self . state . close ( ) ;
@@ -478,10 +495,12 @@ where
478495 }
479496 }
480497 Poll :: Pending => {
498+ #[ cfg( feature = "tracing" ) ]
481499 trace ! ( "maybe_notify; read_from_io blocked" ) ;
482500 return ;
483501 }
484502 Poll :: Ready ( Err ( e) ) => {
503+ #[ cfg( feature = "tracing" ) ]
485504 trace ! ( "maybe_notify; read_from_io error: {}" , e) ;
486505 self . state . close ( ) ;
487506 self . state . error = Some ( crate :: Error :: new_io ( e) ) ;
@@ -720,17 +739,20 @@ where
720739 pub ( crate ) fn poll_flush ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
721740 ready ! ( Pin :: new( & mut self . io) . poll_flush( cx) ) ?;
722741 self . try_keep_alive ( cx) ;
742+ #[ cfg( feature = "tracing" ) ]
723743 trace ! ( "flushed({}): {:?}" , T :: LOG , self . state) ;
724744 Poll :: Ready ( Ok ( ( ) ) )
725745 }
726746
727747 pub ( crate ) fn poll_shutdown ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
728748 match ready ! ( Pin :: new( self . io. io_mut( ) ) . poll_shutdown( cx) ) {
729749 Ok ( ( ) ) => {
750+ #[ cfg( feature = "tracing" ) ]
730751 trace ! ( "shut down IO complete" ) ;
731752 Poll :: Ready ( Ok ( ( ) ) )
732753 }
733754 Err ( e) => {
755+ #[ cfg( feature = "tracing" ) ]
734756 debug ! ( "error shutting down IO: {}" , e) ;
735757 Poll :: Ready ( Err ( e) )
736758 }
@@ -749,7 +771,10 @@ where
749771
750772 // If still in Reading::Body, just give up
751773 match self . state . reading {
752- Reading :: Init | Reading :: KeepAlive => trace ! ( "body drained" ) ,
774+ Reading :: Init | Reading :: KeepAlive => {
775+ #[ cfg( feature = "tracing" ) ]
776+ trace ! ( "body drained" )
777+ } ,
753778 _ => self . close_read ( ) ,
754779 }
755780 }
@@ -765,9 +790,11 @@ where
765790 #[ cfg( feature = "server" ) ]
766791 pub ( crate ) fn disable_keep_alive ( & mut self ) {
767792 if self . state . is_idle ( ) {
793+ #[ cfg( feature = "tracing" ) ]
768794 trace ! ( "disable_keep_alive; closing idle connection" ) ;
769795 self . state . close ( ) ;
770796 } else {
797+ #[ cfg( feature = "tracing" ) ]
771798 trace ! ( "disable_keep_alive; in-progress connection" ) ;
772799 self . state . disable_keep_alive ( ) ;
773800 }
@@ -782,6 +809,7 @@ where
782809 }
783810
784811 pub ( super ) fn on_upgrade ( & mut self ) -> crate :: upgrade:: OnUpgrade {
812+ #[ cfg( feature = "tracing" ) ]
785813 trace ! ( "{}: prepare possible HTTP upgrade" , T :: LOG ) ;
786814 self . state . prepare_upgrade ( )
787815 }
@@ -898,6 +926,7 @@ impl fmt::Debug for Writing {
898926impl std:: ops:: BitAndAssign < bool > for KA {
899927 fn bitand_assign ( & mut self , enabled : bool ) {
900928 if !enabled {
929+ #[ cfg( feature = "tracing" ) ]
901930 trace ! ( "remote disabling keep-alive" ) ;
902931 * self = KA :: Disabled ;
903932 }
@@ -937,19 +966,22 @@ impl KA {
937966
938967impl State {
939968 fn close ( & mut self ) {
969+ #[ cfg( feature = "tracing" ) ]
940970 trace ! ( "State::close()" ) ;
941971 self . reading = Reading :: Closed ;
942972 self . writing = Writing :: Closed ;
943973 self . keep_alive . disable ( ) ;
944974 }
945975
946976 fn close_read ( & mut self ) {
977+ #[ cfg( feature = "tracing" ) ]
947978 trace ! ( "State::close_read()" ) ;
948979 self . reading = Reading :: Closed ;
949980 self . keep_alive . disable ( ) ;
950981 }
951982
952983 fn close_write ( & mut self ) {
984+ #[ cfg( feature = "tracing" ) ]
953985 trace ! ( "State::close_write()" ) ;
954986 self . writing = Writing :: Closed ;
955987 self . keep_alive . disable ( ) ;
@@ -969,6 +1001,7 @@ impl State {
9691001 if let KA :: Busy = self . keep_alive . status ( ) {
9701002 self . idle :: < T > ( ) ;
9711003 } else {
1004+ #[ cfg( feature = "tracing" ) ]
9721005 trace ! (
9731006 "try_keep_alive({}): could keep-alive, but status = {:?}" ,
9741007 T :: LOG ,
0 commit comments