Skip to main content

Crate vibeio_http

Crate vibeio_http 

Source
Expand description

§vibeio-http

High-performance HTTP/1.1, HTTP/2, and 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 and FreeBSD.
  • 100 Continue - Supports automatically sending 100 Continue before the final response.
  • 103 Early Hints - Supports sending 103 Early Hints before 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 and FreeBSD-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
})

Modules§

codech2
HTTP/2 frame codec (RFC 9113 Section 6).
connectionh2
HTTP/2 connection (RFC 9113 Sections 3.5, 5.1, 6.5, 8.1).
errorh2
HTTP/2 error types (RFC 9113 Section 7).
hpackh2 or h3
Primitives shared between HPACK (RFC 7541) and QPACK (RFC 9204).
optionsh2

Structs§

Connectionh2
An HTTP/2 server connection.
ConnectionOptionsh2
Per-connection behavior options.
Http1h1
An HTTP/1.x connection handler.
Http2h2
An HTTP/2 connection handler.
Http1Optionsh1
Configuration options for the HTTP/1.x connection handler.
Http1Zerocopyh1-zerocopy and h1 and (FreeBSD or Linux)
An HTTP/1.x connection handler that uses emulated sendfile for zero-copy response body transmission on Linux and FreeBSD.
Http2Optionsh2
HTTP/2 server configuration.
OnUpgrade
A future that resolves to an Upgraded connection once the HTTP upgrade handshake has been completed by the server side.
PeerSettingsh2
The peer’s current SETTINGS values. Defaults are the RFC 9113 Section 6.5.2 initial values; they change as non-ACK SETTINGS frames arrive.
Upgraded
Represents a successfully upgraded HTTP connection.

Enums§

Incoming
An incoming HTTP request body.

Traits§

HttpProtocol
A trait representing an HTTP protocol (for example, HTTP/1.1, HTTP/2, HTTP/3).

Functions§

install_zerocopyh1
Installs a zero-copy hint on an HTTP response, directing the connection handler to use emulated sendfile (Linux and FreeBSD only) to transmit the body.
prepare_upgrade
Prepares an HTTP upgrade on the given request.
send_early_hints
Sends a 103 Early Hints response for the given request.