Skip to content

Commit bc5ca5f

Browse files
ZexbeJoshua Nelson
authored and
Joshua Nelson
committed
Try finding /index.html when lookup fails
1 parent 1188604 commit bc5ca5f

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/web/rustdoc.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
238238
return Ok(super::redirect(canonical));
239239
}
240240

241-
let path = {
241+
let mut path = {
242242
let mut path = req_path.join("/");
243243
if path.ends_with('/') {
244244
req_path.pop(); // get rid of empty string
@@ -250,7 +250,15 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
250250

251251
let file = match File::from_path(&conn, &path) {
252252
Some(f) => f,
253-
None => return Err(IronError::new(Nope::ResourceNotFound, status::NotFound)),
253+
None => {
254+
//If it fails, we try again with /index.html at the end
255+
path.push_str("/index.html");
256+
req_path.push("index.html");
257+
match File::from_path(&conn, &path) {
258+
Some(f) => f,
259+
None => return Err(IronError::new(Nope::ResourceNotFound, status::NotFound)),
260+
}
261+
},
254262
};
255263

256264
// serve file directly if it's not html
@@ -439,7 +447,11 @@ mod test {
439447
.name("buggy").version("0.1.0")
440448
.build_result_successful(true)
441449
.rustdoc_file("settings.html", b"some data")
450+
.rustdoc_file("directoty_1/index.html", b"some data 1")
451+
.rustdoc_file("directoty_2.html/index.html", b"some data 1")
442452
.rustdoc_file("all.html", b"some data 2")
453+
.rustdoc_file("directory_3/.gitignore", b"*.ext")
454+
.rustdoc_file("directory_4/empty_file_no_ext", b"")
443455
.create()?;
444456
db.fake_release()
445457
.name("buggy").version("0.2.0")
@@ -448,8 +460,12 @@ mod test {
448460
let web = env.frontend();
449461
assert_success("/", web)?;
450462
assert_success("/crate/buggy/0.1.0/", web)?;
463+
assert_success("/buggy/0.1.0/directoty_1/index.html", web)?;
464+
assert_success("/buggy/0.1.0/directoty_2.html/index.html", web)?;
465+
assert_success("/buggy/0.1.0/directory_3/.gitignore", web)?;
451466
assert_success("/buggy/0.1.0/settings.html", web)?;
452467
assert_success("/buggy/0.1.0/all.html", web)?;
468+
assert_success("/buggy/0.1.0/directory_4/empty_file_no_ext", web)?;
453469
Ok(())
454470
});
455471
}
@@ -488,7 +504,9 @@ mod test {
488504
assert_success(base, web)?;
489505
assert_redirect("/dummy/0.3.0/x86_64-unknown-linux-gnu/dummy/", base, web)?;
490506
assert_redirect("/dummy/0.3.0/x86_64-unknown-linux-gnu/all.html", "/dummy/0.3.0/all.html", web)?;
491-
assert_redirect("/dummy/0.3.0/", base, web)
507+
assert_redirect("/dummy/0.3.0/", base, web)?;
508+
assert_redirect("/dummy/0.3.0/index.html",base, web)?;
509+
Ok(())
492510
});
493511
}
494512
}

0 commit comments

Comments
 (0)