@@ -3335,6 +3335,79 @@ fn http1_trailer_fields_not_allowed() {
33353335 assert_eq ! ( body, expected_body) ;
33363336}
33373337
3338+ #[ test]
3339+ fn http1_trailer_fields_allowed_with_comma_separated_te ( ) {
3340+ let body = futures_util:: stream:: once ( async move { Ok ( "hello" . into ( ) ) } ) ;
3341+ let mut headers = HeaderMap :: new ( ) ;
3342+ headers. insert ( "chunky-trailer" , "header data" . parse ( ) . unwrap ( ) ) ;
3343+
3344+ let server = serve ( ) ;
3345+ server
3346+ . reply ( )
3347+ . header ( "transfer-encoding" , "chunked" )
3348+ . header ( "trailer" , "chunky-trailer" )
3349+ . body_stream_with_trailers ( body, headers) ;
3350+ let mut req = connect ( server. addr ( ) ) ;
3351+ req. write_all (
3352+ b"\
3353+ GET / HTTP/1.1\r \n \
3354+ Host: example.domain\r \n \
3355+ Connection: keep-alive\r \n \
3356+ TE: gzip, Trailers\r \n \
3357+ \r \n \
3358+ ",
3359+ )
3360+ . expect ( "writing" ) ;
3361+
3362+ let chunky_trailer_chunk = b"\r \n chunky-trailer: header data\r \n \r \n " ;
3363+ let res = read_until ( & mut req, |buf| buf. ends_with ( chunky_trailer_chunk) ) . expect ( "reading" ) ;
3364+ let sres = s ( & res) ;
3365+
3366+ let date_fragment = "GMT\r \n \r \n " ;
3367+ let pos = sres. find ( date_fragment) . expect ( "find GMT" ) ;
3368+ let body = & sres[ pos + date_fragment. len ( ) ..] ;
3369+
3370+ let expected_body = "5\r \n hello\r \n 0\r \n chunky-trailer: header data\r \n \r \n " ;
3371+ assert_eq ! ( body, expected_body) ;
3372+ }
3373+
3374+ #[ test]
3375+ fn http1_trailer_fields_allowed_with_multiple_te_headers ( ) {
3376+ let body = futures_util:: stream:: once ( async move { Ok ( "hello" . into ( ) ) } ) ;
3377+ let mut headers = HeaderMap :: new ( ) ;
3378+ headers. insert ( "chunky-trailer" , "header data" . parse ( ) . unwrap ( ) ) ;
3379+
3380+ let server = serve ( ) ;
3381+ server
3382+ . reply ( )
3383+ . header ( "transfer-encoding" , "chunked" )
3384+ . header ( "trailer" , "chunky-trailer" )
3385+ . body_stream_with_trailers ( body, headers) ;
3386+ let mut req = connect ( server. addr ( ) ) ;
3387+ req. write_all (
3388+ b"\
3389+ GET / HTTP/1.1\r \n \
3390+ Host: example.domain\r \n \
3391+ Connection: keep-alive\r \n \
3392+ TE: gzip\r \n \
3393+ TE: trailers\r \n \
3394+ \r \n \
3395+ ",
3396+ )
3397+ . expect ( "writing" ) ;
3398+
3399+ let chunky_trailer_chunk = b"\r \n chunky-trailer: header data\r \n \r \n " ;
3400+ let res = read_until ( & mut req, |buf| buf. ends_with ( chunky_trailer_chunk) ) . expect ( "reading" ) ;
3401+ let sres = s ( & res) ;
3402+
3403+ let date_fragment = "GMT\r \n \r \n " ;
3404+ let pos = sres. find ( date_fragment) . expect ( "find GMT" ) ;
3405+ let body = & sres[ pos + date_fragment. len ( ) ..] ;
3406+
3407+ let expected_body = "5\r \n hello\r \n 0\r \n chunky-trailer: header data\r \n \r \n " ;
3408+ assert_eq ! ( body, expected_body) ;
3409+ }
3410+
33383411#[ test]
33393412fn http1_trailer_recv_fields ( ) {
33403413 let server = serve ( ) ;
0 commit comments