Skip to content

Commit 6b45c15

Browse files
Merge pull request #349 from QuietMisdreavus/web-panic
return files directly when serving JS files
2 parents 108a572 + 7be6d92 commit 6b45c15

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/web/rustdoc.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,18 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
111111
if req.url.as_ref().path_segments().unwrap().last().map_or(false, |s| s.ends_with(".js")) {
112112
// javascript files should be handled by the file server instead of erroneously
113113
// redirecting to the crate root page
114-
return rustdoc_html_server_handler(req);
114+
if req.url.as_ref().path_segments().unwrap().count() > 2 {
115+
// this URL is actually from a crate-internal path, serve it there instead
116+
return rustdoc_html_server_handler(req);
117+
} else {
118+
let path = req.url.path();
119+
let path = path.join("/");
120+
let conn = extension!(req, Pool);
121+
match File::from_path(&conn, &path) {
122+
Some(f) => return Ok(f.serve()),
123+
None => return Err(IronError::new(Nope::ResourceNotFound, status::NotFound)),
124+
}
125+
}
115126
} else if req.url.as_ref().path_segments().unwrap().last().map_or(false, |s| s.ends_with(".ico")) {
116127
// route .ico files into their dedicated handler so that docs.rs's favicon is always
117128
// displayed

0 commit comments

Comments
 (0)