Skip to main content

Module body

Module body 

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

AsyncChunkedStream
An async stream that reads a chunked-encoded body.
AsyncContentLengthStream
An async stream that reads a Content-Length body in chunks.
BodyConfig
Configuration for body reading.
ChunkedReader
Parses chunked transfer encoding.
ContentLengthReader
Reads a body with a known Content-Length.
StreamingBodyConfig
Configuration for async body streaming.

Enums§

BodyError
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.