feat: add option --render-try-index (#47)

close #46
This commit is contained in:
sigoden
2022-06-17 08:41:01 +08:00
committed by GitHub
parent 6d7da0363c
commit 5b11bb75dd
5 changed files with 71 additions and 35 deletions

View File

@@ -366,15 +366,17 @@ impl Server {
head_only: bool,
res: &mut Response,
) -> BoxResult<()> {
let path = path.join(INDEX_NAME);
if fs::metadata(&path)
let index_path = path.join(INDEX_NAME);
if fs::metadata(&index_path)
.await
.ok()
.map(|v| v.is_file())
.unwrap_or_default()
{
self.handle_send_file(&path, headers, head_only, res)
self.handle_send_file(&index_path, headers, head_only, res)
.await?;
} else if self.args.render_index_fallback {
self.handle_ls_dir(path, true, head_only, res).await?;
} else {
status_not_found(res)
}