Fix `redirect_to_slash_directory()`

This commit is contained in:
Ali MJ Al-Nasrawy 2021-05-19 13:29:32 +03:00
parent b1de196509
commit e5c178994c
1 changed files with 13 additions and 10 deletions

View File

@ -89,8 +89,10 @@ impl Service<ServiceRequest> for FilesService {
} }
if path.is_dir() { if path.is_dir() {
if let Some(ref redir_index) = self.index { if self.redirect_to_slash
if self.redirect_to_slash && !req.path().ends_with('/') { && !req.path().ends_with('/')
&& (self.index.is_some() || self.show_index)
{
let redirect_to = format!("{}/", req.path()); let redirect_to = format!("{}/", req.path());
return Box::pin(ok(req.into_response( return Box::pin(ok(req.into_response(
@ -100,6 +102,7 @@ impl Service<ServiceRequest> for FilesService {
))); )));
} }
if let Some(ref redir_index) = self.index {
let path = path.join(redir_index); let path = path.join(redir_index);
match NamedFile::open(path) { match NamedFile::open(path) {