Skip to main content

Module http_body

Module http_body 

Source
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§

SseTailOverflow
The unprocessed SSE tail grew past MAX_SSE_TAIL_BYTES without completing an event.

Enums§

BodyReadError
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::TooLarge when it is larger than limit bytes.
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 limit bytes.
read_text_excerpt
Read at most limit bytes of the body as text for a diagnostic message.
read_text_limited
Read the whole body as text, failing when it is larger than limit bytes.