Function axum_server_dual_protocol::bind_dual_protocol

source ยท
pub fn bind_dual_protocol(
    address: SocketAddr,
    config: RustlsConfig,
) -> Server<DualProtocolAcceptor>
Expand description

Create a Server that will bind to the provided address, accepting both HTTP and HTTPS on the same port.

Examples found in repository?
examples/hello-world.rs (line 38)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
async fn main() -> Result<()> {
	let app = Router::new().route("/", routing::get(|| async { "Hello, world!" }));

	let address = SocketAddr::from(([127, 0, 0, 1], 3000));
	println!("Listening on {address}.");
	println!(
		"Connecting to \"http://{address}\" with any path or query will automatically redirect to \"https://{address}\" with the same path and query."
	);

	let certificate = rcgen::generate_simple_self_signed([])?;
	let config = RustlsConfig::from_der(
		vec![certificate.cert.der().to_vec()],
		certificate.key_pair.serialize_der(),
	)
	.await?;

	axum_server_dual_protocol::bind_dual_protocol(address, config)
		.set_upgrade(true)
		.serve(app.into_make_service())
		.await?;

	Ok(())
}