aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/modules/files.rs25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/modules/files.rs b/src/modules/files.rs
index 6a00249..caee799 100644
--- a/src/modules/files.rs
+++ b/src/modules/files.rs
@@ -113,6 +113,18 @@ impl Node for Files {
let metadata = path.metadata()?;
if metadata.file_type().is_dir() {
+ if !rpath.ends_with("/") && self.index {
+ debug!("redirect to trailing slash");
+ let mut r = Response::new(String::new());
+ *r.status_mut() = StatusCode::FOUND;
+ r.headers_mut().insert(
+ LOCATION,
+ HeaderValue::from_str(&format!("{}/", rpath))
+ .map_err(|_| ServiceError::Other)?,
+ );
+ return Ok(r.map(|b| b.map_err(|e| match e {}).boxed()));
+ }
+
debug!("sending index for {path:?}");
if let Ok(indexhtml) = read_to_string({
let path = path.join("index.html");
@@ -128,17 +140,6 @@ impl Node for Files {
}
if self.index {
- if !rpath.ends_with("/") {
- let mut r = Response::new(String::new());
- *r.status_mut() = StatusCode::FOUND;
- r.headers_mut().insert(
- LOCATION,
- HeaderValue::from_str(&format!("{}/", rpath))
- .map_err(|_| ServiceError::Other)?,
- );
- return Ok(r.map(|b| b.map_err(|e| match e {}).boxed()));
- }
-
return index(&path, rpath.to_string())
.await
.map(html_string_response);
@@ -374,7 +375,7 @@ markup::define! {
tr { td { b { a[href=".."] { "../" } } } }
}
@for (name, meta) in files { tr {
- td { a[href=format!("./{name}")] {
+ td { a[href=format!("./{name}{}", if meta.file_type().is_dir() { "/" } else { "" })] {
@name
@if meta.file_type().is_dir() { "/" }
} }