@@ -2640,6 +2640,49 @@ fn http1_trailer_fields() {
2640
2640
assert_eq ! ( body, expected_body) ;
2641
2641
}
2642
2642
2643
+ #[ test]
2644
+ fn http1_trailer_fields_not_allowed ( ) {
2645
+ let body = futures_util:: stream:: once ( async move { Ok ( "hello" . into ( ) ) } ) ;
2646
+ let mut headers = HeaderMap :: new ( ) ;
2647
+ headers. insert ( "chunky-trailer" , "header data" . parse ( ) . unwrap ( ) ) ;
2648
+
2649
+ let server = serve ( ) ;
2650
+ server
2651
+ . reply ( )
2652
+ . header ( "transfer-encoding" , "chunked" )
2653
+ . header ( "trailer" , "chunky-trailer" )
2654
+ . body_stream_with_trailers ( body, headers) ;
2655
+ let mut req = connect ( server. addr ( ) ) ;
2656
+
2657
+ // TE: trailers is not specified in request headers
2658
+ req. write_all (
2659
+ b"\
2660
+ GET / HTTP/1.1\r \n \
2661
+ Host: example.domain\r \n \
2662
+ Connection: keep-alive\r \n \
2663
+ \r \n \
2664
+ ",
2665
+ )
2666
+ . expect ( "writing" ) ;
2667
+
2668
+ let last_chunk = b"\r \n 0\r \n \r \n " ;
2669
+ let res = read_until ( & mut req, |buf| buf. ends_with ( last_chunk) ) . expect ( "reading" ) ;
2670
+ let sres = s ( & res) ;
2671
+
2672
+ let expected_head =
2673
+ "HTTP/1.1 200 OK\r \n transfer-encoding: chunked\r \n trailer: chunky-trailer\r \n " ;
2674
+ assert_eq ! ( & sres[ ..expected_head. len( ) ] , expected_head) ;
2675
+
2676
+ // skip the date header
2677
+ let date_fragment = "GMT\r \n \r \n " ;
2678
+ let pos = sres. find ( date_fragment) . expect ( "find GMT" ) ;
2679
+ let body = & sres[ pos + date_fragment. len ( ) ..] ;
2680
+
2681
+ // no trailer fields should be sent because TE: trailers was not in request headers
2682
+ let expected_body = "5\r \n hello\r \n 0\r \n \r \n " ;
2683
+ assert_eq ! ( body, expected_body) ;
2684
+ }
2685
+
2643
2686
// -------------------------------------------------
2644
2687
// the Server that is used to run all the tests with
2645
2688
// -------------------------------------------------
0 commit comments