@@ -58,6 +58,35 @@ macro_rules! header_value {
5858 } } ;
5959}
6060
61+ pub ( super ) fn parse_headers < T > (
62+ bytes : & mut BytesMut ,
63+ ctx : ParseContext < ' _ > ,
64+ ) -> ParseResult < T :: Incoming >
65+ where
66+ T : Http1Transaction ,
67+ {
68+ // If the buffer is empty, don't bother entering the span, it's just noise.
69+ if bytes. is_empty ( ) {
70+ return Ok ( None ) ;
71+ }
72+
73+ let span = trace_span ! ( "parse_headers" ) ;
74+ let _s = span. enter ( ) ;
75+ T :: parse ( bytes, ctx)
76+ }
77+
78+ pub ( super ) fn encode_headers < T > (
79+ enc : Encode < ' _ , T :: Outgoing > ,
80+ dst : & mut Vec < u8 > ,
81+ ) -> crate :: Result < Encoder >
82+ where
83+ T : Http1Transaction ,
84+ {
85+ let span = trace_span ! ( "encode_headers" ) ;
86+ let _s = span. enter ( ) ;
87+ T :: encode ( enc, dst)
88+ }
89+
6190// There are 2 main roles, Client and Server.
6291
6392pub ( crate ) enum Client { }
@@ -70,9 +99,7 @@ impl Http1Transaction for Server {
7099 const LOG : & ' static str = "{role=server}" ;
71100
72101 fn parse ( buf : & mut BytesMut , ctx : ParseContext < ' _ > ) -> ParseResult < RequestLine > {
73- if buf. is_empty ( ) {
74- return Ok ( None ) ;
75- }
102+ debug_assert ! ( !buf. is_empty( ) , "parse called with empty buf" ) ;
76103
77104 let mut keep_alive;
78105 let is_http_11;
@@ -614,11 +641,10 @@ impl Http1Transaction for Client {
614641 const LOG : & ' static str = "{role=client}" ;
615642
616643 fn parse ( buf : & mut BytesMut , ctx : ParseContext < ' _ > ) -> ParseResult < StatusCode > {
644+ debug_assert ! ( !buf. is_empty( ) , "parse called with empty buf" ) ;
645+
617646 // Loop to skip information status code headers (100 Continue, etc).
618647 loop {
619- if buf. is_empty ( ) {
620- return Ok ( None ) ;
621- }
622648 // Unsafe: see comment in Server Http1Transaction, above.
623649 let mut headers_indices: [ HeaderIndices ; MAX_HEADERS ] = unsafe { mem:: uninitialized ( ) } ;
624650 let ( len, status, version, headers_len) = {
@@ -688,6 +714,12 @@ impl Http1Transaction for Client {
688714 wants_upgrade : is_upgrade,
689715 } ) ) ;
690716 }
717+
718+ // Parsing a 1xx response could have consumed the buffer, check if
719+ // it is empty now...
720+ if buf. is_empty ( ) {
721+ return Ok ( None ) ;
722+ }
691723 }
692724 }
693725
0 commit comments