Skip to content

Commit a24b37a

Browse files
tweak how in-crate javascript files are served
1 parent a83da34 commit a24b37a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/web/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ impl CratesfyiHandler {
170170
router.get("/:crate/:version/",
171171
rustdoc::rustdoc_redirector_handler,
172172
"crate_version_");
173-
router.get("/:crate/:version/*.js",
174-
rustdoc::rustdoc_redirector_handler,
175-
"crate_version_js");
176173
router.get("/:crate/:version/settings.html",
177174
rustdoc::rustdoc_html_server_handler,
178175
"crate_version_settings_html");

src/web/rustdoc.rs

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
104104
Ok(resp)
105105
}
106106

107+
// this unwrap is safe because iron urls are always able to use `path_segments`
108+
// i'm using this instead of `req.url.path()` to avoid allocating the Vec, and also to avoid
109+
// keeping the borrow alive into the return statement
110+
if req.url.as_ref().path_segments().unwrap().last().map_or(false, |s| s.ends_with(".js")) {
111+
// javascript files should be handled by the file server instead of erroneously
112+
// redirecting to the crate root page
113+
return rustdoc_html_server_handler(req);
114+
}
115+
107116
let router = extension!(req, Router);
108117
// this handler should never called without crate pattern
109118
let crate_name = cexpect!(router.find("crate"));

0 commit comments

Comments
 (0)