From a515d508ac3d2c565d429a9a255788754263ff3f Mon Sep 17 00:00:00 2001 From: Johann150 Date: Thu, 19 Nov 2020 22:21:57 +0100 Subject: [PATCH] do not redirect on empty path also fixed the check for a trailing slash --- src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index ec6602b..2fdaa62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -156,10 +156,12 @@ async fn send_response(url: Url, stream: &mut W) -> Result { path.extend(segments); } if async_std::fs::metadata(&path).await?.is_dir() { - if url.as_str().ends_with('/') { + if url.path().ends_with('/') || url.path().is_empty() { + // if the path ends with a slash or the path is empty, the links will work the same + // without a redirect path.push("index.gmi"); } else { - // Send a redirect when the URL for a directory has no trailing slash. + // if client is not redirected, links may not work as expected without trailing slash return respond(stream, "31", &[url.as_str(), "/"]).await; } }