Expand description
HTTP codec module for encoding and decoding HTTP messages
This module provides functionality for streaming HTTP message processing, including request decoding and response encoding. It uses a state machine pattern to handle both headers and payload data efficiently.
§Architecture
The codec module is organized into several components:
-
Request handling:
RequestDecoder
: Decodes incoming HTTP requests- Header parsing via [
header
] module - Payload decoding via [
body
] module
-
Response handling:
ResponseEncoder
: Encodes outgoing HTTP responses- Header encoding via [
header
] module - Payload encoding via [
body
] module
§Example
use micro_http::codec::{RequestDecoder, ResponseEncoder};
use tokio_util::codec::{Decoder, Encoder};
use bytes::BytesMut;
// Decode incoming request
let mut decoder = RequestDecoder::new();
let mut request_buffer = BytesMut::new();
let request = decoder.decode(&mut request_buffer);
// Encode outgoing response
let mut encoder = ResponseEncoder::new();
let mut response_buffer = BytesMut::new();
// ... encode response ...
§Features
- Streaming processing of HTTP messages
- Support for chunked transfer encoding
- Content-Length based payload handling
- Efficient header parsing and encoding
- State machine based processing
Structs§
- Request
Decoder - A decoder for HTTP requests that handles both headers and payload
- Response
Encoder - A encoder for HTTP responses that handles both headers and payload