Struct axum_server::tls_rustls::RustlsConfig [−][src]
pub struct RustlsConfig { /* fields omitted */ }
tls-rustls
only.Expand description
Rustls configuration.
Implementations
Create config from Arc<
ServerConfig
>
.
Create config from DER-encoded data.
The certificate must be DER-encoded X.509.
The private key must be DER-encoded ASN.1 in either PKCS#8 or PKCS#1 format.
Create config from PEM formatted data.
Certificate and private key must be in PEM format.
Create config from PEM formatted files.
Contents of certificate file and private key file must be in PEM format.
Examples found in repository
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
More examples
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
async fn https_server() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 3443));
println!("https listening on {}", addr);
axum_server::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
// Spawn a task to reload tls.
tokio::spawn(reload(config.clone()));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
Get inner Arc<
ServerConfig
>
.
Reload config from Arc<
ServerConfig
>
.
Reload config from DER-encoded data.
The certificate must be DER-encoded X.509.
The private key must be DER-encoded ASN.1 in either PKCS#8 or PKCS#1 format.
Reload config from PEM formatted data.
Certificate and private key must be in PEM format.
Reload config from PEM formatted files.
Contents of certificate file and private key file must be in PEM format.
Examples found in repository
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
async fn reload(config: RustlsConfig) {
// Wait for 20 seconds.
sleep(Duration::from_secs(20)).await;
println!("reloading rustls configuration");
// Reload rustls configuration from new files.
config
.reload_from_pem_file(
"examples/self-signed-certs/reload/cert.pem",
"examples/self-signed-certs/reload/key.pem",
)
.await
.unwrap();
println!("rustls configuration reloaded");
}
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for RustlsConfig
impl Send for RustlsConfig
impl Sync for RustlsConfig
impl Unpin for RustlsConfig
impl !UnwindSafe for RustlsConfig
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more