@@ -2081,6 +2081,79 @@ async def test_http_payload_zstandard(self, protocol: BaseProtocol) -> None:
20812081 assert b"zstd data" == out ._buffer [0 ]
20822082 assert out .is_eof ()
20832083
2084+ @pytest .mark .skipif (zstandard is None , reason = "zstandard is not installed" )
2085+ async def test_http_payload_zstandard_multi_frame (
2086+ self , protocol : BaseProtocol
2087+ ) -> None :
2088+ frame1 = zstandard .compress (b"first" )
2089+ frame2 = zstandard .compress (b"second" )
2090+ payload = frame1 + frame2
2091+ out = aiohttp .StreamReader (protocol , 2 ** 16 , loop = asyncio .get_running_loop ())
2092+ p = HttpPayloadParser (
2093+ out ,
2094+ length = len (payload ),
2095+ compression = "zstd" ,
2096+ headers_parser = HeadersParser (),
2097+ )
2098+ p .feed_data (payload )
2099+ assert b"firstsecond" == b"" .join (out ._buffer )
2100+ assert out .is_eof ()
2101+
2102+ @pytest .mark .skipif (zstandard is None , reason = "zstandard is not installed" )
2103+ async def test_http_payload_zstandard_multi_frame_chunked (
2104+ self , protocol : BaseProtocol
2105+ ) -> None :
2106+ frame1 = zstandard .compress (b"chunk1" )
2107+ frame2 = zstandard .compress (b"chunk2" )
2108+ out = aiohttp .StreamReader (protocol , 2 ** 16 , loop = asyncio .get_running_loop ())
2109+ p = HttpPayloadParser (
2110+ out ,
2111+ length = len (frame1 ) + len (frame2 ),
2112+ compression = "zstd" ,
2113+ headers_parser = HeadersParser (),
2114+ )
2115+ p .feed_data (frame1 )
2116+ p .feed_data (frame2 )
2117+ assert b"chunk1chunk2" == b"" .join (out ._buffer )
2118+ assert out .is_eof ()
2119+
2120+ @pytest .mark .skipif (zstandard is None , reason = "zstandard is not installed" )
2121+ async def test_http_payload_zstandard_frame_split_mid_chunk (
2122+ self , protocol : BaseProtocol
2123+ ) -> None :
2124+ frame1 = zstandard .compress (b"AAAA" )
2125+ frame2 = zstandard .compress (b"BBBB" )
2126+ combined = frame1 + frame2
2127+ split_point = len (frame1 ) + 3 # 3 bytes into frame2
2128+ out = aiohttp .StreamReader (protocol , 2 ** 16 , loop = asyncio .get_running_loop ())
2129+ p = HttpPayloadParser (
2130+ out ,
2131+ length = len (combined ),
2132+ compression = "zstd" ,
2133+ headers_parser = HeadersParser (),
2134+ )
2135+ p .feed_data (combined [:split_point ])
2136+ p .feed_data (combined [split_point :])
2137+ assert b"AAAABBBB" == b"" .join (out ._buffer )
2138+ assert out .is_eof ()
2139+
2140+ @pytest .mark .skipif (zstandard is None , reason = "zstandard is not installed" )
2141+ async def test_http_payload_zstandard_many_small_frames (
2142+ self , protocol : BaseProtocol
2143+ ) -> None :
2144+ parts = [f"part{ i } " .encode () for i in range (10 )]
2145+ payload = b"" .join (zstandard .compress (p ) for p in parts )
2146+ out = aiohttp .StreamReader (protocol , 2 ** 16 , loop = asyncio .get_running_loop ())
2147+ p = HttpPayloadParser (
2148+ out ,
2149+ length = len (payload ),
2150+ compression = "zstd" ,
2151+ headers_parser = HeadersParser (),
2152+ )
2153+ p .feed_data (payload )
2154+ assert b"" .join (parts ) == b"" .join (out ._buffer )
2155+ assert out .is_eof ()
2156+
20842157
20852158class TestDeflateBuffer :
20862159 async def test_feed_data (self , protocol : BaseProtocol ) -> None :
0 commit comments