Skip to content

Commit 27b90da

Browse files
daxpeddajakobhellermann
authored andcommitted
Automatically upgrade HTTP requests to HTTPS
1 parent 73b7ed8 commit 27b90da

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ wasm-bindgen-cli-support = "0.2"
1818

1919
axum = { version = "0.5", default-features = false, features = ["http1", "headers"] }
2020
axum-server = { version = "0.4", features = ["tls-rustls"] }
21+
axum-server-dual-protocol = "0.2"
2122
tokio = { version = "1.11", default-features = false, features = ["rt-multi-thread"] }
2223
tower-http = { version = "0.3", features = ["compression-full", "fs", "set-header", "trace"] }
2324
tower = "0.4"

src/server.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use axum::response::{Html, IntoResponse, Response};
66
use axum::routing::{get, get_service};
77
use axum::{Router, TypedHeader};
88
use axum_server::tls_rustls::RustlsConfig;
9+
use axum_server_dual_protocol::ServerExt;
910
use tower::ServiceBuilder;
1011
use tower_http::compression::CompressionLayer;
1112
use tower_http::services::ServeDir;
@@ -73,7 +74,10 @@ pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<(
7374
.await?;
7475

7576
tracing::info!("starting webserver at https://{}", addr);
76-
axum_server::bind_rustls(addr, config).serve(app.into_make_service()).await?;
77+
axum_server_dual_protocol::bind_dual_protocol(addr, config)
78+
.set_upgrade(true)
79+
.serve(app.into_make_service())
80+
.await?;
7781
} else {
7882
tracing::info!("starting webserver at http://{}", addr);
7983
axum_server::bind(addr).serve(app.into_make_service()).await?;

0 commit comments

Comments
 (0)