vibeio-http
High-performance HTTP server primitives for the vibeio runtime.
vibeio-http provides HTTP/1.0, HTTP/1.1, HTTP/2, and HTTP/3 connection
handlers behind a shared HttpProtocol trait. Each handler receives an
http::Request<Incoming> and returns an http::Response<B>, where
B: http_body::Body<Data = bytes::Bytes>.
Highlights
- HTTP/1.x, HTTP/2, and HTTP/3 handlers with a common interface
- Streaming request/response bodies and trailers
- Automatic
100 Continuesupport 103 Early Hintssupport viasend_early_hints- HTTP/1 upgrade support (
prepare_upgrade/OnUpgrade) - Linux and FreeBSD zero-copy response sending for HTTP/1.x (
h1-zerocopyfeature) - Graceful shutdown support for all protocol handlers via
CancellationToken - Custom HTTP/2 and HTTP/3 implementations, without dependencies on Hyperium's
h2andh3crates
Installation
[]
= "0.4"
By default, this crate enables: h1, h1-zerocopy, and h2.
Feature flags
| Feature | Enables |
|---|---|
h1 |
HTTP/1.0 / HTTP/1.1 connection handler |
h1-zerocopy |
Linux / FreeBSD zero-copy HTTP/1.x response sending (splice-based) |
h2 |
HTTP/2 connection handler (in-house) |
h3 |
HTTP/3 connection handler (native RFC 9114 implementation) |
h3-quinn |
QUIC transport adapter for h3 (vibeio_http::quinn, built on quinn) |
For a smaller build, disable default features and opt in explicitly:
[]
= { = "0.4", = false, = ["h1"] }
Quickstart (HTTP/1.1)
use Bytes;
use Response;
use Full;
use TcpListener;
use RuntimeBuilder;
use ;
Early hints (103)
Use send_early_hints from your handler before returning the final response.
Notes:
- HTTP/2 and HTTP/3: available by default
- HTTP/1.x: requires
Http1Options::enable_early_hints(true)
use ;
use Empty;
use send_early_hints;
let handler = ;
HTTP options
Http1Options, Http2Options, and Http3Options all expose:
- handshake / accept timeouts
- automatic
100 Continue - direct access to the underlying protocol builders (
h2_builder, ...)
The native Http3Options additionally exposes QPACK and header/stream limits:
qpack_max_table_capacity(u64)— max dynamic table capacity advertisedqpack_blocked_streams(u64)— max number of blocked QPACK streamsmax_field_section_size(Option<u64>)— header size limitenable_connect_protocol(bool)— extendedCONNECTsupportaccept_timeout(Option<Duration>)/handshake_timeout(Option<Duration>)send_continue_response(bool)/send_date_header(bool)
Http1Options additionally supports request head size / header count limits,
request head read timeout, automatic Date header injection, optional 103 Early Hints, and a vectored write toggle.
HTTP/1 upgrades
For upgrade workflows (for example WebSocket-style handoff), call
prepare_upgrade(&mut request) in your handler and await the returned
OnUpgrade future after sending a 101 Switching Protocols response.
The resolved Upgraded type implements tokio::io::AsyncRead + AsyncWrite.
Linux/FreeBSD zero-copy (HTTP/1.x)
When built with h1-zerocopy on Linux or FreeBSD:
- Convert your handler with
.zerocopy() - Mark responses with
unsafe install_zerocopy(response, raw_fd)
Responses carrying that extension are sent via kernel-assisted transfer. Other responses fall back to normal HTTP/1 writes.
Graceful shutdown
Http1, Http2, and Http3 expose:
.graceful_shutdown_token
Cancel the token to stop accepting new work and shut down the connection cleanly.
Benchmarks
The crate ships Criterion benchmarks for the hot paths:
# QPACK codec (table sizes 0/512/4096, Huffman on/off)
# Native HTTP/3 server throughput + latency over a quinn loopback
Crate API at a glance
HttpProtocol: common protocol trait (handle,handle_with_error_fn)Incoming: type-erased request body type used in all handlerssend_early_hints: send a103 Early Hintsinterim responseHttp1/Http1OptionsHttp2/Http2OptionsHttp3/Http3Optionsvibeio_http::quinn::Connection: QUIC transport adapter (withh3-quinn)prepare_upgrade,OnUpgrade,Upgraded(HTTP/1 upgrade flow)