Expand description
Size-bounded reads of HTTP response bodies.
reqwest::Response::text(), ::bytes() and ::json() buffer the entire
body, so a misbehaving or hostile endpoint (or a proxy error page) can
exhaust memory before any caller-side check runs. Every response read goes
through these helpers instead, which reject up front when Content-Length
already exceeds the cap and otherwise stop pulling chunk()s the moment
the cap is crossed, so peak memory is bounded even when the server lies
about or omits Content-Length.
Bodies are decoded as UTF-8 (lossily). The JSON and text APIs these callers
talk to are UTF-8, and reqwest’s charset sniffing is not worth giving up a
hard memory bound for.
Structs§
- SseTail
Overflow - The unprocessed SSE tail grew past
MAX_SSE_TAIL_BYTESwithout completing an event.
Enums§
- Body
Read Error - Why a bounded body read did not produce a complete body.
Constants§
- API_
BODY_ LIMIT_ BYTES - Cap for ordinary API payloads (agent protocol, non-streaming completions).
- CONTROL_
BODY_ LIMIT_ BYTES - Cap for small control-plane responses (OAuth token exchanges, registries).
- ERROR_
BODY_ LIMIT_ BYTES - Cap for error-path bodies read only to build a diagnostic message.
- MAX_
SSE_ TAIL_ BYTES - Maximum bytes retained for one incomplete SSE event.
Functions§
- check_
sse_ tail_ bound - Fail-closed bound for the unprocessed SSE tail.
- read_
body_ limited - Read the whole body, failing with
BodyReadError::TooLargewhen it is larger thanlimitbytes. - read_
control_ text - Read a control-plane response (OAuth, registry) as text under
CONTROL_BODY_LIMIT_BYTES. - read_
json_ limited - Read the whole body and parse it as JSON, failing when it is larger than
limitbytes. - read_
text_ excerpt - Read at most
limitbytes of the body as text for a diagnostic message. - read_
text_ limited - Read the whole body as text, failing when it is larger than
limitbytes.