@@ -395,7 +395,7 @@ fn decode_trailers_frame(mut buf: Bytes) -> Result<Option<HeaderMap>, Status> {
395
395
for ( i, b) in buf. iter ( ) . enumerate ( ) {
396
396
if b == & b'\r' && buf. get ( i + 1 ) == Some ( & b'\n' ) {
397
397
let trailer = temp_buf. copy_to_bytes ( i - cursor_pos) ;
398
- cursor_pos = i;
398
+ cursor_pos = i + 2 ;
399
399
trailers. push ( trailer) ;
400
400
if temp_buf. has_remaining ( ) {
401
401
temp_buf. get_u8 ( ) ;
@@ -548,14 +548,14 @@ mod tests {
548
548
#[ test]
549
549
fn find_trailers_buffered ( ) {
550
550
// Byte version of this:
551
- // b"\0\0\0\0L\n$975738af-1a17-4aea-b887-ed0bbced6093\x1a$da609e9b-f470-4cc0-a691-3fd6a005a436\x80\0\0\0\x0fgrpc-status:0\r\n"
552
- let buf = [
553
- 0 , 0 , 0 , 0 , 76 , 10 , 36 , 57 , 55 , 53 , 55 , 51 , 56 , 97 , 102 , 45 , 49 , 97 , 49 , 55 , 45 , 52 ,
554
- 97 , 101 , 97 , 45 , 98 , 56 , 56 , 55 , 45 , 101 , 100 , 48 , 98 , 98 , 99 , 101 , 100 , 54 , 48 , 57 ,
555
- 51 , 26 , 36 , 100 , 97 , 54 , 48 , 57 , 101 , 57 , 98 , 45 , 102 , 52 , 55 , 48 , 45 , 52 , 99 , 99 , 48 ,
556
- 45 , 97 , 54 , 57 , 49 , 45 , 51 , 102 , 100 , 54 , 97 , 48 , 48 , 53 , 97 , 52 , 51 , 54 , 128 , 0 , 0 , 0 ,
557
- 15 , 103 , 114 , 112 , 99 , 45 , 115 , 116 , 97 , 116 , 117 , 115 , 58 , 48 , 13 , 10 ,
558
- ] ;
551
+ let buf = b"\0 \0 \0 \0 L\n $975738af-1a17-4aea-b887-ed0bbced6093\x1a $da609e9b-f470-4cc0-a691-3fd6a005a436\x80 \0 \0 \0 \x0f grpc-status:0\r \n grpc-message: \r \n request_id:d0e56d4d10ab4c85b0882c3467049522 \r \n a:1 \r \n b:2 \r \n " ;
552
+ // let buf = [
553
+ // 0, 0, 0, 0, 76, 10, 36, 57, 55, 53, 55, 51, 56, 97, 102, 45, 49, 97, 49, 55, 45, 52,
554
+ // 97, 101, 97, 45, 98, 56, 56, 55, 45, 101, 100, 48, 98, 98, 99, 101, 100, 54, 48, 57,
555
+ // 51, 26, 36, 100, 97, 54, 48, 57, 101, 57, 98, 45, 102, 52, 55, 48, 45, 52, 99, 99, 48,
556
+ // 45, 97, 54, 57, 49, 45, 51, 102, 100, 54, 97, 48, 48, 53, 97, 52, 51, 54, 128, 0, 0, 0,
557
+ // 15, 103, 114, 112, 99, 45, 115, 116, 97, 116, 117, 115, 58, 48, 13, 10,
558
+ // ];
559
559
560
560
let out = find_trailers ( & buf[ ..] ) . unwrap ( ) ;
561
561
@@ -565,7 +565,8 @@ mod tests {
565
565
. unwrap ( )
566
566
. unwrap ( ) ;
567
567
let status = trailers. get ( "grpc-status" ) . unwrap ( ) ;
568
- assert_eq ! ( status. to_str( ) . unwrap( ) , "0" )
568
+ assert_eq ! ( status. to_str( ) . unwrap( ) , "0" ) ;
569
+ dbg ! ( trailers) ;
569
570
}
570
571
571
572
#[ test]
@@ -612,4 +613,21 @@ mod tests {
612
613
613
614
assert_eq ! ( out. code( ) , Code :: Internal ) ;
614
615
}
616
+
617
+ #[ test]
618
+ fn decode_multiple_trailers ( ) {
619
+ 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 " ;
620
+
621
+ let trailers = decode_trailers_frame ( Bytes :: copy_from_slice ( & buf[ ..] ) )
622
+ . unwrap ( )
623
+ . unwrap ( ) ;
624
+
625
+ let mut expected = HeaderMap :: new ( ) ;
626
+ expected. insert ( "grpc-status" , "0" . parse ( ) . unwrap ( ) ) ;
627
+ expected. insert ( "grpc-message" , "" . parse ( ) . unwrap ( ) ) ;
628
+ expected. insert ( "a" , "1" . parse ( ) . unwrap ( ) ) ;
629
+ expected. insert ( "b" , "2" . parse ( ) . unwrap ( ) ) ;
630
+
631
+ assert_eq ! ( trailers, expected) ;
632
+ }
615
633
}
0 commit comments