Skip to main content

Module server

Module server 

Source
Expand description

High-performance Web Server Engine supporting HTTP/1.1, HTTP/2, and HTTP/3.

The server module provides the Server struct, which wraps a CompiledRouter and dispatches incoming network streams for all supported HTTP versions.

§Protocol support

MethodProtocolFeature flag
serve_httpHTTP/1.1 plain TCP (+ HTTP/2 cleartext “h2c” with http2)(always)
serve_httpsHTTP/1.1 + HTTP/2 over TLStls
serve_https_configSame but with custom ServerConfigtls
serve_h3HTTP/3 over QUIChttp3
start_allAll of the above via PEM cert/key stringscert-gen
serve_all_acmeAll of the above, certs managed by Let’s Encryptlets-encrypt
serve_torHTTP/1.1 (+ h2c) over a native Tor .onion hidden servicetor
serve_i2pHTTP/1.1 (+ h2c) over a native I2P .b32.i2p eepsite (⚠️ breaks forbid(unsafe_code))i2p

§Publishing over more than one transport at once

Each serve_* method above consumes its Server and blocks for that one transport’s lifetime — the right building block for a single-transport deployment. To publish the same app over several transports at once (e.g. clearnet HTTPS and a .onion mirror and a .i2p mirror, all from one process), prefer MultiServer over hand-rolling tokio::spawn + tokio::select! around the individual serve_* calls yourself — it owns exactly that boilerplate:

use tachyon_web::{Router, Server, get};

let app: Router = Router::new().route("/", get(|| async { "hi" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;

Server::new(app)
    .with_http(listener)
    // .with_onion(onion_config)   // requires the `tor` feature
    // .with_i2p(i2p_config)       // requires the `i2p` feature
    .serve()
    .await?;

Modules§

i2p
Native I2P .b32.i2p eepsite support (see the i2p feature).
tor
Native Tor .onion hidden-service support (see the tor feature).

Structs§

HttpsServer
An HTTPS server ready to be run.
MultiServer
Builds a group of transports to drive concurrently from one Server — see the module docs.
RustlsConfig
Configuration for custom rustls server.
Server
Main server configuration and runner.

Functions§

bind_rustls
Create an HTTPS server bound to the given SocketAddr using the provided RustlsConfig.
serve
Start serving requests from the given TcpListener using the provided Router.
serve_http_redirect_and_challenges
Runs a plain HTTP listener that serves two functions: