@@ -184,6 +184,28 @@ fn test_chunked_with_compression() {
184184 assert_chunked_encoding ( headers, false , None ) ;
185185}
186186
187+ fn build_chunked_multi_header_body ( encoding : & str ) -> String {
188+ format ! (
189+ "Host: example.com\r \n \
190+ Content-Type: text/html; charset=utf-8\r \n \
191+ {encoding}: br\r \n \
192+ {encoding}: deflate\r \n \
193+ {encoding}: identity\r \n \
194+ {encoding}: gzip\r \n \
195+ {encoding}: zstd\r \n \
196+ Transfer-Encoding: chunked\r \n \r \n "
197+ )
198+ }
199+
200+ #[ test]
201+ fn test_chunked_with_compression_multi_header ( ) {
202+ assert_chunked_encoding (
203+ & build_chunked_multi_header_body ( TRANSFER_ENCODING ) ,
204+ false ,
205+ None ,
206+ ) ;
207+ }
208+
187209#[ test]
188210fn test_chunked_with_compression_extra_raw ( ) {
189211 let headers = "Host: example.com\r \n \
@@ -194,6 +216,15 @@ fn test_chunked_with_compression_extra_raw() {
194216 assert_chunked_encoding ( headers, false , Some ( INPUT . into ( ) ) ) ;
195217}
196218
219+ #[ test]
220+ fn test_chunked_with_compression_multi_header_extra_raw ( ) {
221+ assert_chunked_encoding (
222+ & build_chunked_multi_header_body ( TRANSFER_ENCODING ) ,
223+ false ,
224+ Some ( INPUT . into ( ) ) ,
225+ ) ;
226+ }
227+
197228#[ test]
198229fn test_chunked_with_compress_extra_compressed_together ( ) {
199230 let body = all_compressed_data ( ) ; // len 53
@@ -237,6 +268,50 @@ fn test_chunked_with_compress_extra_compressed_together() {
237268 assert_eq ! ( tm. into_bytes( ) , VERIFY_SINGLE_HEADER_BODY_ONLY ) ;
238269}
239270
271+ #[ test]
272+ fn test_chunked_with_compress_extra_compressed_together_multi_header ( ) {
273+ let body = all_compressed_data ( ) ; // len 53
274+ let mut chunk_vec = vec ! [
275+ ChunkType :: Size ( "10\r \n " . into( ) ) ,
276+ ChunkType :: Chunk ( body[ 0 ..10 ] . into( ) ) ,
277+ ChunkType :: Size ( "10\r \n " . into( ) ) ,
278+ ChunkType :: Chunk ( body[ 10 ..20 ] . into( ) ) ,
279+ ChunkType :: Size ( "10\r \n " . into( ) ) ,
280+ ChunkType :: Chunk ( body[ 20 ..30 ] . into( ) ) ,
281+ ChunkType :: Size ( "10\r \n " . into( ) ) ,
282+ ChunkType :: Chunk ( body[ 30 ..40 ] . into( ) ) ,
283+ ChunkType :: Size ( "10\r \n " . into( ) ) ,
284+ ] ;
285+
286+ for chunk in chunk_vec. iter_mut ( ) {
287+ if let ChunkType :: Chunk ( chunk) = chunk {
288+ chunk. extend_from_slice ( "\r \n " . as_bytes ( ) ) ;
289+ }
290+ }
291+ let chunk_body = Body :: Chunked ( chunk_vec) ;
292+ let extra = BytesMut :: from ( & body[ 40 ..] ) ;
293+
294+ let headers = build_chunked_multi_header_body ( TRANSFER_ENCODING ) ;
295+
296+ let mut tm = TestMessage :: build (
297+ BytesMut :: from ( & headers[ ..] ) ,
298+ chunk_body,
299+ Some ( extra) ,
300+ ) ;
301+
302+ let mut buf = BytesMut :: new ( ) ;
303+ let mut state = DecodeState :: init ( & mut tm, & mut buf) ;
304+ state = state. try_next ( ) . unwrap ( ) ;
305+ assert ! ( matches!( state, DecodeState :: TransferEncoding ( ..) ) ) ;
306+
307+ state = state. try_next ( ) . unwrap ( ) ;
308+ assert ! ( matches!( state, DecodeState :: UpdateContentLength ( ..) ) ) ;
309+
310+ state = state. try_next ( ) . unwrap ( ) ;
311+ assert ! ( state. is_ended( ) ) ;
312+ assert_eq ! ( tm. into_bytes( ) , VERIFY_SINGLE_HEADER_BODY_ONLY ) ;
313+ }
314+
240315#[ test]
241316fn test_chunked_with_compress_extra_compressed_separate ( ) {
242317 let body = build_all_compressed_chunk_body ( ) ;
@@ -262,6 +337,29 @@ fn test_chunked_with_compress_extra_compressed_separate() {
262337 assert_eq ! ( tm. into_bytes( ) , VERIFY_SINGLE_HEADER_BODY_AND_EXTRA ) ;
263338}
264339
340+ #[ test]
341+ fn test_chunked_with_compress_extra_compressed_separate_multi_header ( ) {
342+ let body = build_all_compressed_chunk_body ( ) ;
343+ let extra = all_compressed_data ( ) ;
344+
345+ let headers = build_chunked_multi_header_body ( TRANSFER_ENCODING ) ;
346+
347+ let mut tm =
348+ TestMessage :: build ( BytesMut :: from ( & headers[ ..] ) , body, Some ( extra) ) ;
349+
350+ let mut buf = BytesMut :: new ( ) ;
351+ let mut state = DecodeState :: init ( & mut tm, & mut buf) ;
352+ state = state. try_next ( ) . unwrap ( ) ;
353+ assert ! ( matches!( state, DecodeState :: TransferEncoding ( ..) ) ) ;
354+
355+ state = state. try_next ( ) . unwrap ( ) ;
356+ assert ! ( matches!( state, DecodeState :: UpdateContentLength ( ..) ) ) ;
357+
358+ state = state. try_next ( ) . unwrap ( ) ;
359+ assert ! ( state. is_ended( ) ) ;
360+ assert_eq ! ( tm. into_bytes( ) , VERIFY_SINGLE_HEADER_BODY_AND_EXTRA ) ;
361+ }
362+
265363/// Ce
266364#[ test]
267365fn test_chunked_with_ce_compression ( ) {
@@ -358,5 +456,3 @@ fn test_chunked_with_ce_compress_extra_compressed_separate() {
358456 assert ! ( state. is_ended( ) ) ;
359457 assert_eq ! ( tm. into_bytes( ) , VERIFY_SINGLE_HEADER_BODY_AND_EXTRA ) ;
360458}
361-
362- // Partial
0 commit comments