Skip to content

Commit f9bf3b6

Browse files
committed
simplify redirect code w/ updated deps
1 parent 9e63c16 commit f9bf3b6

File tree

2 files changed

+33
-38
lines changed

2 files changed

+33
-38
lines changed

Cargo.lock

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/service/mod.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::{convert::Infallible, sync::Arc, time::Duration};
1+
use std::{convert::Infallible, time::Duration};
22

33
use rama::{
44
Layer as _, Service,
5-
error::{ErrorContext as _, OpaqueError},
5+
error::OpaqueError,
66
http::{
77
Body, HeaderName, HeaderValue, Request, Response,
88
headers::StrictTransportSecurity,
@@ -13,7 +13,7 @@ use rama::{
1313
},
1414
service::{fs::DirectoryServeMode, redirect::RedirectHttpToHttps, web::Router},
1515
},
16-
net::http::uri::UriMatchReplaceRule,
16+
net::http::uri::UriMatchReplaceDomain,
1717
utils::include_dir::include_dir,
1818
};
1919

@@ -38,10 +38,8 @@ fn apply_common_middleware(
3838

3939
pub async fn load_http_service()
4040
-> Result<impl Service<Request, Response = Response, Error = Infallible>, OpaqueError> {
41-
let app = RedirectHttpToHttps::new().with_match_replace_uri_rule(
42-
UriMatchReplaceRule::try_new("http://www.*", "https://www.$1")
43-
.context("create APEX to root uri replace rule")?,
44-
);
41+
let app =
42+
RedirectHttpToHttps::new().with_rewrite_uri_rule(UriMatchReplaceDomain::drop_prefix_www());
4543
Ok(apply_common_middleware(app))
4644
}
4745

@@ -53,10 +51,7 @@ pub async fn load_https_service()
5351
DirectoryServeMode::AppendIndexHtml,
5452
);
5553

56-
let middlewares = UriMatchRedirectLayer::permanent(Arc::new(
57-
UriMatchReplaceRule::try_new("https://www.*", "https://$1")
58-
.context("create www to APEX redirect rule")?,
59-
));
54+
let middlewares = UriMatchRedirectLayer::permanent(UriMatchReplaceDomain::drop_prefix_www());
6055

6156
Ok(apply_common_middleware(middlewares.into_layer(app)))
6257
}

0 commit comments

Comments
 (0)