@@ -2025,6 +2025,79 @@ async def test_http_payload_zstandard(self, protocol: BaseProtocol) -> None:
20252025 assert b"zstd data" == out ._buffer [0 ]
20262026 assert out .is_eof ()
20272027
2028+ @pytest .mark .skipif (zstandard is None , reason = "zstandard is not installed" )
2029+ async def test_http_payload_zstandard_multi_frame (
2030+ self , protocol : BaseProtocol
2031+ ) -> None :
2032+ frame1 = zstandard .compress (b"first" )
2033+ frame2 = zstandard .compress (b"second" )
2034+ payload = frame1 + frame2
2035+ out = aiohttp .StreamReader (protocol , 2 ** 16 , loop = asyncio .get_running_loop ())
2036+ p = HttpPayloadParser (
2037+ out ,
2038+ length = len (payload ),
2039+ compression = "zstd" ,
2040+ headers_parser = HeadersParser (),
2041+ )
2042+ p .feed_data (payload )
2043+ assert b"firstsecond" == b"" .join (out ._buffer )
2044+ assert out .is_eof ()
2045+
2046+ @pytest .mark .skipif (zstandard is None , reason = "zstandard is not installed" )
2047+ async def test_http_payload_zstandard_multi_frame_chunked (
2048+ self , protocol : BaseProtocol
2049+ ) -> None :
2050+ frame1 = zstandard .compress (b"chunk1" )
2051+ frame2 = zstandard .compress (b"chunk2" )
2052+ out = aiohttp .StreamReader (protocol , 2 ** 16 , loop = asyncio .get_running_loop ())
2053+ p = HttpPayloadParser (
2054+ out ,
2055+ length = len (frame1 ) + len (frame2 ),
2056+ compression = "zstd" ,
2057+ headers_parser = HeadersParser (),
2058+ )
2059+ p .feed_data (frame1 )
2060+ p .feed_data (frame2 )
2061+ assert b"chunk1chunk2" == b"" .join (out ._buffer )
2062+ assert out .is_eof ()
2063+
2064+ @pytest .mark .skipif (zstandard is None , reason = "zstandard is not installed" )
2065+ async def test_http_payload_zstandard_frame_split_mid_chunk (
2066+ self , protocol : BaseProtocol
2067+ ) -> None :
2068+ frame1 = zstandard .compress (b"AAAA" )
2069+ frame2 = zstandard .compress (b"BBBB" )
2070+ combined = frame1 + frame2
2071+ split_point = len (frame1 ) + 3 # 3 bytes into frame2
2072+ out = aiohttp .StreamReader (protocol , 2 ** 16 , loop = asyncio .get_running_loop ())
2073+ p = HttpPayloadParser (
2074+ out ,
2075+ length = len (combined ),
2076+ compression = "zstd" ,
2077+ headers_parser = HeadersParser (),
2078+ )
2079+ p .feed_data (combined [:split_point ])
2080+ p .feed_data (combined [split_point :])
2081+ assert b"AAAABBBB" == b"" .join (out ._buffer )
2082+ assert out .is_eof ()
2083+
2084+ @pytest .mark .skipif (zstandard is None , reason = "zstandard is not installed" )
2085+ async def test_http_payload_zstandard_many_small_frames (
2086+ self , protocol : BaseProtocol
2087+ ) -> None :
2088+ parts = [f"part{ i } " .encode () for i in range (10 )]
2089+ payload = b"" .join (zstandard .compress (p ) for p in parts )
2090+ out = aiohttp .StreamReader (protocol , 2 ** 16 , loop = asyncio .get_running_loop ())
2091+ p = HttpPayloadParser (
2092+ out ,
2093+ length = len (payload ),
2094+ compression = "zstd" ,
2095+ headers_parser = HeadersParser (),
2096+ )
2097+ p .feed_data (payload )
2098+ assert b"" .join (parts ) == b"" .join (out ._buffer )
2099+ assert out .is_eof ()
2100+
20282101
20292102class TestDeflateBuffer :
20302103 async def test_feed_data (self , protocol : BaseProtocol ) -> None :
0 commit comments