diff options
author | metamuffin <metamuffin@disroot.org> | 2025-03-24 22:01:10 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-03-24 22:01:10 +0100 |
commit | 8068c9ace1b07fa9b1a4f73a8bf3a93313dc236f (patch) | |
tree | 740f66b8f89e477a5e5d13d49743b19e92014752 | |
parent | 8b3f8e8b2858f4ab65daf8c20be6917e96bc0ff8 (diff) | |
download | gnix-8068c9ace1b07fa9b1a4f73a8bf3a93313dc236f.tar gnix-8068c9ace1b07fa9b1a4f73a8bf3a93313dc236f.tar.bz2 gnix-8068c9ace1b07fa9b1a4f73a8bf3a93313dc236f.tar.zst |
Include trailing slash in directory index for dirs
-rw-r--r-- | src/modules/files.rs | 25 |
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() { "/" } } } |