Expand description
HTTP version detection and handling module.
This module provides functionality to detect the HTTP version (HTTP/1.x or HTTP/2) of incoming connections and route them accordingly. It is designed to work seamlessly with monoio’s asynchronous runtime and the service_async framework.
§Key Components
H2Detect: The main service component responsible for HTTP version detection.H2DetectError: Error type for version detection operations.
§Features
- Automatic detection of HTTP/2 connections based on the client preface
- Seamless handling of both HTTP/1.x and HTTP/2 connections
- Integration with
service_asyncfor easy composition in service stacks - Efficient I/O handling using monoio’s asynchronous primitives
§Usage
This service is typically used as part of a larger service stack, placed before the main HTTP handling logic. Here’s a basic example:
ⓘ
use service_async::{layer::FactoryLayer, stack::FactoryStack};
let config = Config { /* ... */ };
let stack = FactoryStack::new(config)
.push(HttpCoreService::layer())
.push(H2Detect::layer())
// ... other layers ...
;
let service = stack.make_async().await.unwrap();
// Use the service to handle incoming connections§Performance Considerations
- Uses efficient buffering to minimize I/O operations during version detection
- Implements zero-copy techniques where possible to reduce memory overhead
Structs§
- H2Detect
- Service for detecting HTTP version and routing connections accordingly.