"""Bounded HTTP body read (leaf module, no intra-package imports). `response.content.read(n)` returns whatever is buffered, not n bytes, so it silently truncates large or chunked bodies (and web feeds/pages parse to garbage). This accumulates decompressed chunks up to a hard cap instead. """ CHUNK = 65536 async def read_capped(response, max_bytes: int) -> bytes: buf = bytearray() async for chunk in response.content.iter_chunked(CHUNK): buf.extend(chunk) if len(buf) > max_bytes: break return bytes(buf[:max_bytes])