Expand description
HTTP request body handling.
This module provides body reading with support for:
- Content-Length based reading with size limits
- Chunked transfer encoding parsing
- Streaming API for large bodies
- Integration points for async I/O
§Body Size Limits
By default, bodies are limited to 1MB. This prevents denial-of-service attacks via large payloads. The limit is configurable per-request.
§Streaming
Large bodies can be read incrementally via the body reader API, which supports async I/O integration with checkpoints.
§Example
ⓘ
use fastapi_http::body::{BodyConfig, ContentLengthReader};
let config = BodyConfig::default().with_max_size(1024 * 1024);
let mut reader = ContentLengthReader::new(body_bytes, 100, &config)?;
let body = reader.read_all()?;Structs§
- Async
Chunked Stream - An async stream that reads a chunked-encoded body.
- Async
Content Length Stream - An async stream that reads a Content-Length body in chunks.
- Body
Config - Configuration for body reading.
- Chunked
Reader - Parses chunked transfer encoding.
- Content
Length Reader - Reads a body with a known Content-Length.
- Streaming
Body Config - Configuration for async body streaming.
Enums§
- Body
Error - Error types for body reading.
Constants§
- DEFAULT_
MAX_ BODY_ SIZE - Default maximum body size (1MB).
- DEFAULT_
STREAMING_ THRESHOLD - Default threshold for enabling streaming (64KB).
Functions§
- create_
chunked_ stream - Create a streaming body from a chunked transfer-encoded body.
- create_
content_ length_ stream - Create a streaming body from a Content-Length body.
- parse_
body - Parse a request body from a buffer given the body length indicator.
- parse_
body_ with_ consumed - Parse a request body and return both the decoded body and bytes consumed.
- validate_
content_ length - Validates body size against Content-Length header before reading.