File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -393,11 +393,15 @@ fn decode_trailers_frame(mut buf: Bytes) -> Result<Option<HeaderMap>, Status> {
393
393
let mut cursor_pos = 0 ;
394
394
395
395
for ( i, b) in buf. iter ( ) . enumerate ( ) {
396
+ // if we are at a trailer delimiter (\r\n)
396
397
if b == & b'\r' && buf. get ( i + 1 ) == Some ( & b'\n' ) {
398
+ // read the bytes of the trailer passed so far
397
399
let trailer = temp_buf. copy_to_bytes ( i - cursor_pos) ;
398
- cursor_pos = i;
400
+ // increment cursor beyond the delimiter
401
+ cursor_pos = i + 2 ;
399
402
trailers. push ( trailer) ;
400
403
if temp_buf. has_remaining ( ) {
404
+ // advance buf beyond the delimiters
401
405
temp_buf. get_u8 ( ) ;
402
406
temp_buf. get_u8 ( ) ;
403
407
}
@@ -612,4 +616,21 @@ mod tests {
612
616
613
617
assert_eq ! ( out. code( ) , Code :: Internal ) ;
614
618
}
619
+
620
+ #[ test]
621
+ fn decode_multiple_trailers ( ) {
622
+ let buf = b"\x80 \0 \0 \0 \x0f grpc-status:0\r \n grpc-message:\r \n a:1\r \n b:2\r \n " ;
623
+
624
+ let trailers = decode_trailers_frame ( Bytes :: copy_from_slice ( & buf[ ..] ) )
625
+ . unwrap ( )
626
+ . unwrap ( ) ;
627
+
628
+ let mut expected = HeaderMap :: new ( ) ;
629
+ expected. insert ( "grpc-status" , "0" . parse ( ) . unwrap ( ) ) ;
630
+ expected. insert ( "grpc-message" , "" . parse ( ) . unwrap ( ) ) ;
631
+ expected. insert ( "a" , "1" . parse ( ) . unwrap ( ) ) ;
632
+ expected. insert ( "b" , "2" . parse ( ) . unwrap ( ) ) ;
633
+
634
+ assert_eq ! ( trailers, expected) ;
635
+ }
615
636
}
You can’t perform that action at this time.
0 commit comments