@@ -125,6 +125,7 @@ def handler(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
125125 with pytest .raises (ResponseTooLargeError ) as caught :
126126 _read_capped (resp , 1000 , resp .request )
127127 assert caught .value .reason == "streamed" # compressed CL (small) passed; decoded tripped
128+ assert caught .value .content_length == len (raw ) # the declared (compressed) length, threaded through
128129 finally :
129130 resp .close ()
130131 client .close ()
@@ -192,6 +193,23 @@ def handler(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
192193 await client .aclose ()
193194
194195
196+ async def test_read_capped_async_gzip_bomb_trips_on_decoded_bytes () -> None :
197+ raw = gzip .compress (b"A" * 100_000 )
198+
199+ def handler (request : httpx2 .Request ) -> httpx2 .Response : # noqa: ARG001
200+ return httpx2 .Response (200 , headers = {"content-encoding" : "gzip" }, content = raw )
201+
202+ client , resp = await _async_stream (handler )
203+ try :
204+ with pytest .raises (ResponseTooLargeError ) as caught :
205+ await _read_capped_async (resp , 1000 , resp .request )
206+ assert caught .value .reason == "streamed" # compressed CL (small) passed; decoded tripped
207+ assert caught .value .content_length == len (raw ) # the declared (compressed) length, threaded through
208+ finally :
209+ await resp .aclose ()
210+ await client .aclose ()
211+
212+
195213async def test_read_capped_async_head_with_large_declared_length_not_rejected () -> None :
196214 def handler (request : httpx2 .Request ) -> httpx2 .Response : # noqa: ARG001
197215 return httpx2 .Response (200 , headers = {"content-length" : "50000000" })
0 commit comments