hyperlane 23.2.0

A lightweight, high-performance, and cross-platform Rust HTTP server library built on Tokio. It simplifies modern web service development by providing built-in support for middleware, WebSocket, Server-Sent Events (SSE), and raw TCP communication. With a unified and ergonomic API across Windows, Linux, and MacOS, it enables developers to build robust, scalable, and event-driven network applications with minimal overhead and maximum flexibility.
Documentation

Hyperlane

High-Performance Multi-Protocol Asynchronous Rust HTTP/1.x · HTTP/2 · HTTP/3 Web Framework & Plugin Ecosystem

Crates.io Docs.rs Rust CI Rust 2024 MIT license

API Docs · Quick Start · Workspace Architecture · Plugin Ecosystem · Benchmarks


Overview

Hyperlane is a high-performance asynchronous Rust web framework built on Tokio. It serves HTTP/1.0, HTTP/1.1, HTTP/2 (h2c/h2), HTTP/3 (QUIC), WebSocket, Server-Sent Events (SSE), gRPC, JSON-RPC, and Model Context Protocol (MCP) workloads with explicit control over the request and response lifecycle, strict RFC 9110/9112 wire conformance, and 26 opt-in zero-overhead plugins.

flowchart LR
    App["User Service\nRoutes · Middleware · Hooks"] --> Facade["hyperlane\nFacade Crate"]
    Facade --> Core["hyperlane-core\nHTTP/1.x · HTTP/2 · HTTP/3 · io_uring"]
    Facade --> Macros["hyperlane-macros\n#[route] · #[send] · #[hyperlane]"]
    Core --> Wire["http-type · http-constant · http-compress"]
    App --> Plugins["26 Opt-In Plugins\nAuth · Cache · Circuit Breaker · Concurrency · CORS · Gateway · IP Filter ..."]
    Plugins --> Client["http-request\nSync & Async H1/H2 Client"]
    Tooling["hyperlane-cli (hyperlane fmt) · hyperlane-performance"] -.-> Facade

Quick Start

Create a binary crate targeting Rust edition 2024 and add hyperlane:

cargo new hello-hyperlane
cd hello-hyperlane
cargo add hyperlane

Replace src/main.rs with:

use hyperlane::{Context, Server, ServerConfig, ServerError, ServerHook, Status, Stream, tokio};

const ADDRESS: &str = "127.0.0.1:3000";
const ROOT_PATH: &str = "/";
const GREETING: &str = "Hello from Hyperlane!\n";

struct Hello;

impl ServerHook for Hello {
    async fn new(_: &mut Stream, _: &mut Context) -> Self {
        Self
    }

    #[hyperlane::send]
    async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status {
        ctx.get_mut_response().set_body(GREETING);
        Status::Reject
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<ServerError>> {
    let mut config: ServerConfig = ServerConfig::default();
    config.set_address(ADDRESS);

    let mut server: Server = Server::default();
    server.server_config(config).route::<Hello>(ROOT_PATH);

    let control = server.run().await?;
    println!("Listening on http://{ADDRESS}");
    control.wait().await;
    Ok(())
}

Run cargo run and query the endpoint:

curl -fsS http://127.0.0.1:3000/

#[hyperlane::send] serializes and flushes the response built by the hook; Status::Reject stops the remaining pipeline so downstream hooks do not send a second response.


Capabilities

Area Support
HTTP/1.x HTTP/1.0 and HTTP/1.1 over TCP with optional TLS, keep-alive Context reset, and bounded chunked decoding
HTTP/2 Cleartext (h2c) with prior knowledge or TLS with ALPN (h2)
HTTP/3 QUIC with TLS (quinn + h3)
Routing & Hooks Synchronous radix routing ({param:regex} anchored), typed request/response middleware, and ServerHook lifecycle
Realtime & RPC WebSocket rooms, WHATWG SSE, raw TCP, gRPC over HTTP/2, JSON-RPC 2.0, and Streamable HTTP MCP
Tooling hyperlane fmt (delegating to crate-cli Prettier-aligned formatting + Hyperlane attribute normalization) and CPU-pinned benchmarks

Select the wire protocol per listener via ServerConfig.


Workspace Architecture

All 35 crates share a unified version in root Cargo.toml (Rust edition 2024):

Core, Wire & Tooling Crates (9)

Crate Path Responsibility
hyperlane . (src/) Facade crate re-exporting hyperlane-core and hyperlane-macros
hyperlane-core core/ Multi-protocol async server (HTTP/1.x, HTTP/2, HTTP/3), router, Context, ServerHook, Linux io_uring
hyperlane-macros macros/ Procedural attribute macros (#[route], #[hyperlane], #[send], #[host], #[referer], etc.)
http-type type/ RFC 9110/9112 wire parsers/builders, Request, Response, Stream, Cookie, MultipartFormData, WebSocket, Status
http-constant constant/ Canonical HTTP header, method, status, and symbol constants
http-compress compress/ Bounded gzip, deflate, and brotli codecs (MAX_DECOMPRESSED_BYTES = 64 MiB) and Accept-Encoding negotiation
http-request request/ Sync & async HTTP/1.1 + HTTP/2 client with pooling, TLS resumption, retries, multipart, and HTTP/SOCKS5 proxies
hyperlane-cli cli/ Developer CLI (hyperlane fmt layered on crate-cli, watch, new, template)
hyperlane-performance performance/ Official CPU-pinned native & Docker loadgen and deterministic alloc-count benchmark harness

Opt-In Plugin Ecosystem (26)

Every plugin is opt-in and transparent (Status::Continue) when unconfigured (see plugin/README.md):

Plugin Crate Path Responsibility
hyperlane-plugin-auth plugin/auth/ HS256 JWT (kid rotation), API key, HTTP Basic, RBAC AuthPrincipal, AuthHook
hyperlane-plugin-cache plugin/cache/ 64-way sharded bounded cache, single-flight coalescing, CacheRequestHook/CacheResponseHook
hyperlane-plugin-circuit-breaker plugin/circuit_breaker/ Route/prefix-scoped lock-free atomic sliding-window 5xx circuit breaker with half-open probe gating & 503
hyperlane-plugin-concurrency plugin/concurrency/ Lock-free atomic global & per-prefix in-flight concurrency limiter, RAII Context permits, load shedding 503
hyperlane-plugin-cors plugin/cors/ Precompiled zero-alloc CORS headers, origin policies, preflight OPTIONS, Vary merging
hyperlane-plugin-gateway plugin/gateway/ Reverse proxy & API gateway over pooled http-request with balancing, circuit breaker, GCRA limiter
hyperlane-plugin-grpc plugin/grpc/ gRPC over HTTP/2 5-byte framing, bounded compression, status codes 0..=16, grpc-timeout
hyperlane-plugin-health plugin/health/ /healthz, /livez, /readyz concurrent async probes, snapshot TTL cache, lock-free drain flag
hyperlane-plugin-idempotency plugin/idempotency/ HTTP Idempotency-Key middleware, XxHash3_64 payload fingerprint, 64-shard replay store & in-flight lock
hyperlane-plugin-ip-filter plugin/ip_filter/ Trusted-proxy right-to-left real IP extraction, /8 radix IPv4/IPv6 CIDR allow/denylist & prebuilt 403
hyperlane-plugin-logger plugin/logger/ Non-blocking buffered console/file logger with Plain/JSON formats and CRLF/ANSI sanitization
hyperlane-plugin-mcp plugin/mcp/ Streamable HTTP Model Context Protocol server with session TTLs and Origin DNS-rebinding guard
hyperlane-plugin-metrics plugin/metrics/ Lock-free atomic counters, gauges, latency histograms, and Prometheus OpenMetrics /metrics endpoint
hyperlane-plugin-mq plugin/mq/ Async MessageBroker trait and 64-shard InMemoryBroker with consumer groups, TTL, retries, DLQ
hyperlane-plugin-negotiate plugin/negotiate/ Accept-Encoding compression and conditional 304 Not Modified ETag middlewares
hyperlane-plugin-rate-limit plugin/rate_limit/ 64-way sharded lock-free atomic GCRA & fixed-window rate limiter with RFC RateLimit-* headers
hyperlane-plugin-rewrite plugin/rewrite/ Zero-alloc URL normalization, HTTPS/canonical-host redirects, XxHash3_64 exact/prefix/regex rewrites
hyperlane-plugin-rpc plugin/rpc/ JSON-RPC 2.0 XxHash3_64 router with concurrent batch/notification dispatch and payload caps
hyperlane-plugin-security plugin/security/ Prebuilt HSTS/CSP/COOP/COEP/CORP headers, stateless HMAC-SHA256 CSRF, host/URI/traversal guards
hyperlane-plugin-session plugin/session/ 64-shard bounded session store, HMAC-SHA256 signed cookies, dirty-tracked zero-write reads
hyperlane-plugin-shutdown plugin/shutdown/ Graceful shutdown coordinator with SIGINT/SIGTERM arming, RAII drain guards, LIFO callbacks
hyperlane-plugin-sse plugin/sse/ WHATWG SSE framing, CRLF sanitization, 64-way sharded topic pub/sub, Last-Event-ID replay
hyperlane-plugin-static-files plugin/static_files/ Traversal-proof static server, MIME table, hot-file cache, .br/.gz sidecars, Range (206/416)
hyperlane-plugin-tracing plugin/tracing/ Lock-free 128-bit W3C Trace Context (traceparent/tracestate), X-Request-Id, Server-Timing
hyperlane-plugin-webhook plugin/webhook/ Constant-time pure-Rust HMAC-SHA256 webhook verification (hex/base64/Stripe), skew guard & 64-shard replay cache
hyperlane-plugin-websocket plugin/websocket/ Room-based WebSocket broadcast with lag recovery, lifecycle hooks, and opt-in WebSocketPlugin

Protocol Notes

These notes describe the current checkout. For behavior of an installed version, see release notes and API documentation.

  • Conditional requests: Request::matches_if_none_match(current_etag) performs allocation-free weak ETag comparison (including repeated headers, quoted tags with commas, and *). Callers control 304 Not Modified / 412 Precondition Failed status selection.
  • HTTP/1.1 request bodies: Transfer-Encoding: chunked is decoded transparently with bounded body limits; chunk extensions and trailers are consumed.
  • Default request errors: Unparseable or oversized requests emit an empty error response (closing HTTP/1.x connections or completing H2/H3 streams) unless overridden by request-error hooks.

Benchmarks

The performance workflow runs the CPU-pinned Docker harness against baseline and candidate revisions in the same measurement window across h1, h1-tls, h2c, h2-tls, h3, and deterministic alloc-count.


Verification & Governance

Before pushing or opening a pull request, run the full local quality gate:

cargo run -p hyperlane-cli -- fmt
cargo run -p hyperlane-cli -- fmt
cargo run -p hyperlane-cli -- fmt --check
cargo fmt --all -- --check
cargo clippy --workspace --all-features --all-targets -- -D warnings
cargo test --workspace --all-features
cargo check --release --workspace --all-features

License

Hyperlane is distributed under the MIT License.