Skip to content

Commit 3fc0676

Browse files
authored
Merge pull request #476 from jyn514/trailing-slash
allow trailing slash in standard-library redirects
2 parents a2bfe83 + aa9954b commit 3fc0676

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/web/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ impl CratesfyiHandler {
9595
}
9696

9797
pub fn new() -> CratesfyiHandler {
98+
const DOC_RUST_LANG_ORG_REDIRECTS: [&str; 5] = [
99+
"alloc", "core", "proc_macro", "std", "test"
100+
];
101+
98102
let mut router = Router::new();
99103
router.get("/", releases::home_page, "index");
100104
router.get("/style.css", style_css_handler, "style_css");
@@ -105,11 +109,15 @@ impl CratesfyiHandler {
105109
router.get("/opensearch.xml", opensearch_xml_handler, "opensearch_xml");
106110

107111
// Redirect standard library crates to rust-lang.org
108-
router.get("/alloc", rustdoc::RustLangRedirector::new("alloc"), "alloc");
109-
router.get("/core", rustdoc::RustLangRedirector::new("core"), "core");
110-
router.get("/proc_macro", rustdoc::RustLangRedirector::new("proc_macro"), "proc_macro");
111-
router.get("/std", rustdoc::RustLangRedirector::new("std"), "std");
112-
router.get("/test", rustdoc::RustLangRedirector::new("test"), "test");
112+
for redirect in DOC_RUST_LANG_ORG_REDIRECTS.iter() {
113+
let redirector = rustdoc::RustLangRedirector::new(redirect);
114+
router.get(&format!("/{}", redirect), redirector, redirect);
115+
116+
// allow trailing slashes
117+
let redirector = rustdoc::RustLangRedirector::new(redirect);
118+
let target = format!("/{}/", redirect);
119+
router.get(&target, redirector, &target[1..]);
120+
}
113121

114122
router.get("/releases", releases::recent_releases_handler, "releases");
115123
router.get("/releases/feed",

0 commit comments

Comments
 (0)