Skip to content

return files directly when serving JS files #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,18 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
if req.url.as_ref().path_segments().unwrap().last().map_or(false, |s| s.ends_with(".js")) {
// javascript files should be handled by the file server instead of erroneously
// redirecting to the crate root page
return rustdoc_html_server_handler(req);
if req.url.as_ref().path_segments().unwrap().count() > 2 {
// this URL is actually from a crate-internal path, serve it there instead
return rustdoc_html_server_handler(req);
} else {
let path = req.url.path();
let path = path.join("/");
let conn = extension!(req, Pool);
match File::from_path(&conn, &path) {
Some(f) => return Ok(f.serve()),
None => return Err(IronError::new(Nope::ResourceNotFound, status::NotFound)),
}
}
} else if req.url.as_ref().path_segments().unwrap().last().map_or(false, |s| s.ends_with(".ico")) {
// route .ico files into their dedicated handler so that docs.rs's favicon is always
// displayed
Expand Down