Expand description
§vibeio-http
High-performance HTTP/1.1, HTTP/2, and experimental HTTP/3 server implementation
for the vibeio async runtime.
vibeio-http provides protocol-specific connection handlers behind a common
HttpProtocol trait. Handlers receive an http::Request<Incoming>
and return an http::Response<B> where B implements
http_body::Body with bytes::Bytes chunks.
§Feature highlights
- Zero-copy static file serving - supports zero-copy response sending for static file serving on Linux.
- 100 Continue - Supports automatically sending
100 Continuebefore the final response. - 103 Early Hints - Supports sending
103 Early Hintsbefore the final response.
§Feature flags
h1: Enables HTTP/1.x support.h2: Enables HTTP/2 support.h3: Enables HTTP/3 support.h1-zerocopy: Enables Linux-only zero-copy response sending for HTTP/1.x.
§Early hints
Use send_early_hints from a request handler to send 103 Early Hints
before the final response.
§Example
use bytes::Bytes;
use http::Response;
use http_body_util::Full;
use vibeio::net::TcpListener;
use vibeio::RuntimeBuilder;
use vibeio_http::{Http1, Http1Options, HttpProtocol};
let runtime = RuntimeBuilder::new().enable_timer(true).build()?;
runtime.block_on(async {
let listener = TcpListener::bind("127.0.0.1:8080")?;
let (stream, _) = listener.accept().await?;
stream.set_nodelay(true)?;
Http1::new(stream.into_poll()?, Http1Options::default())
.handle(|_request| async move {
let response = Response::new(Full::new(Bytes::from_static(b"Hello World")));
Ok::<_, std::convert::Infallible>(response)
})
.await
})Structs§
- Http1
h1 - An HTTP/1.x connection handler.
- Http2
h2 - An HTTP/2 connection handler.
- Http1
Options - Configuration options for the HTTP/1.x connection handler.
- Http1
Zerocopy Linux and h1-zerocopy - An HTTP/1.x connection handler that uses emulated sendfile for zero-copy response body transmission on Linux.
- Http2
Options - Configuration options for the HTTP/2 connection handler.
- OnUpgrade
- A future that resolves to an
Upgradedconnection once the HTTP upgrade handshake has been completed by the server side. - Upgraded
- Represents a successfully upgraded HTTP connection.
Enums§
- Incoming
- An incoming HTTP request body.
Traits§
- Http
Protocol - A trait representing an HTTP protocol (for example, HTTP/1.1, HTTP/2, HTTP/3).
Functions§
- install_
zerocopy ⚠ - Installs a zero-copy hint on an HTTP response, directing the connection handler to use emulated sendfile (Linux only) to transmit the body.
- prepare_
upgrade - Prepares an HTTP upgrade on the given request.
- send_
early_ hints - Sends a
103 Early Hintsresponse for the given request.