Module protocol

Source
Expand description

Core HTTP protocol abstractions and implementations.

This module provides the fundamental building blocks for HTTP protocol handling, including request/response processing, body streaming, and error handling. The design focuses on providing clean abstractions while maintaining high performance and memory efficiency.

§Architecture

The protocol module is organized into several key components:

  • Message Handling ([message]): Core message types and payload processing

    • Message: Represents either headers or payload chunks
    • PayloadItem: Handles individual payload chunks and EOF
    • PayloadSize: Tracks payload size information
  • Request Processing ([request]): Request header handling

    • RequestHeader: Wraps HTTP request headers with additional functionality
  • Response Processing ([response]): Response header handling

    • ResponseHead: Type alias for response headers before body attachment
  • Body Streaming (body): Efficient body handling implementation

    • [ReqBody]: Consumer side implementing http_body::Body
    • [ReqBodySender]: Producer side for streaming body chunks
  • Error Handling ([error]): Comprehensive error types

§Design Goals

  1. Memory Efficiency

    • Stream request/response bodies instead of buffering
    • Implement proper backpressure mechanisms
  2. Clean Abstractions

    • Provide intuitive interfaces for protocol handling
    • Hide implementation complexity from consumers
  3. Protocol Correctness

    • Ensure proper HTTP protocol compliance
    • Handle edge cases and error conditions gracefully
  4. Performance

    • Minimize allocations and copies
    • Support concurrent processing where beneficial

§Example Usage

The protocol module is typically used through the connection layer rather than directly. However, understanding its components is crucial for implementing custom handlers or extending functionality.

See individual module documentation for specific usage examples.

Modules§

body
HTTP request body handling implementation.

Structs§

RequestHeader
Represents an HTTP request header.

Enums§

HttpError
The top-level error type for HTTP operations
Message
Represents a HTTP message that can either be a header or payload.
ParseError
Errors that occur during HTTP request parsing
PayloadItem
Represents an item in the HTTP message payload stream.
PayloadSize
Represents the size information of an HTTP payload.
SendError
Errors that occur during HTTP response generation and sending

Type Aliases§

ResponseHead
Type alias for HTTP response headers.