Module axum_server::tls[][src]

This is supported on crate feature tls-rustls only.
Expand description

Tls implementation for HTTP server.

TlsServer can be used just like Server to serve apps.

Examples

Hello World

use axum::{
    handler::get,
    Router,
};

use axum_server::Server;

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, world" }));

    Server::new()
        .bind("127.0.0.1:3000")
        .bind_rustls("127.0.0.1:3443")
        .private_key_file("examples/self-signed-certs/key.pem")
        .certificate_file("examples/self-signed-certs/cert.pem")
        .serve(app)
        .await
        .unwrap();
}

Uri Scheme

use axum::{extract::Extension, handler::get, http::uri::Scheme, Router};
use axum_server::Server;

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(handler));

    Server::new()
        .bind("127.0.0.1:3000")
        .bind_rustls("127.0.0.1:3443")
        .private_key_file("examples/self-signed-certs/key.pem")
        .certificate_file("examples/self-signed-certs/cert.pem")
        .serve(app)
        .await
        .unwrap();
}

async fn handler(Extension(scheme): Extension<Scheme>) -> String {
    format!("scheme: {}", scheme)
}

Structs

A struct that can be passed to TlsServer to reload tls configuration.

Configurable HTTP and HTTPS server, supporting HTTP/1.1 and HTTP2.