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
qpackh3
QPACK (RFC 9204) header compression for HTTP/3.
quinnh3-quinn and h3
quinn transport adapter (behind the h3-quinn feature).
transporth3
QUIC transport abstraction for the HTTP/3 implementation.

Structs§

Connectionh2
An HTTP/2 server connection.
ConnectionOptionsh2
Per-connection behavior options.
FrameDecoderh3
Incremental HTTP/3 frame decoder.
Http1h1
An HTTP/1.x connection handler.
Http2h2
An HTTP/2 connection handler.
Http3h3
An HTTP/3 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.
Http3Optionsh3
Configuration options for the HTTP/3 connection handler.
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.
Settingsh3
A parsed SETTINGS frame payload (RFC 9114 Section 7.2.4).
Upgraded
Represents a successfully upgraded HTTP connection.

Enums§

Frameh3
An HTTP/3 frame (RFC 9114 Section 7.2).
FrameErrorh3
Errors raised by FrameDecoder::next_frame.
H3Errorh3
Typed HTTP/3 application errors (RFC 9114 Section 8.1).
Incoming
An incoming HTTP request body.
TransportErrorh3
Errors surfaced by the QUIC transport abstraction (crate::h3::transport).

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.