#https #axum-server #https-server #http #server #server-port #web


Host a HTTP and HTTPS server on the same port with axum-server

8 releases (5 breaking)

0.6.0 Dec 22, 2023
0.5.2 Jun 16, 2023
0.4.0 May 4, 2023
0.3.0 Nov 26, 2022
0.1.0 Jul 28, 2022

#127 in HTTP server

Download history 269/week @ 2023-12-18 73/week @ 2023-12-25 143/week @ 2024-01-01 349/week @ 2024-01-08 297/week @ 2024-01-15 420/week @ 2024-01-22 505/week @ 2024-01-29 527/week @ 2024-02-05 405/week @ 2024-02-12 585/week @ 2024-02-19 497/week @ 2024-02-26 458/week @ 2024-03-04 490/week @ 2024-03-11 371/week @ 2024-03-18 517/week @ 2024-03-25 594/week @ 2024-04-01

2,021 downloads per month
Used in 4 crates (3 directly)


448 lines


Crates.io Version Live Build Status Docs.rs Documentation Main Documentation


Provides utilities to host a axum-server server that accepts the HTTP and HTTPS protocol on the same port. See bind_dual_protocol().

A common use case for this is if a HTTPS server is hosted on a non-traditional port, having no corresponding HTTP port. This can be an issue for clients who try to connect over HTTP and get a connection reset error. See ServerExt::set_upgrade().


The simplest way to start is to use bind_dual_protocol():

let app = Router::new().route(
	routing::get(|request: Request<Body>| async move {
		match request.extensions().get::<Protocol>().unwrap() {
			Protocol::Tls => "Hello, secure World!",
			Protocol::Plain => "Hello, insecure World!",

// User-supplied certificate and private key.
let config = RustlsConfig::from_der(certificate, private_key).await?;

axum_server_dual_protocol::bind_dual_protocol(address, config)

We now have a server accepting both HTTP and HTTPS requests! Now we can automatically upgrade incoming HTTP requests to HTTPS using ServerExt::set_upgrade() like this:

use axum_server_dual_protocol::ServerExt;

axum_server_dual_protocol::bind_dual_protocol(address, config)

Alternatively UpgradeHttpLayer can be used:

let app = Router::new()
	.route("/", routing::get(|| async { "Hello, world!" }))


As this library heavily relies on axum-server, axum, tower and hyper the MSRV depends on theirs. At the point of time this was written the highest MSRV was axum with 1.66.


See the CHANGELOG file for details.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~463K SLoC