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,17 +89,20 @@ impl Service<ServiceRequest> for FilesService {
}
if path.is_dir() {
if self.redirect_to_slash
&& !req.path().ends_with('/')
&& (self.index.is_some() || self.show_index)
{
let redirect_to = format!("{}/", req.path());
return Box::pin(ok(req.into_response(
HttpResponse::Found()
.insert_header((header::LOCATION, redirect_to))
.finish(),
)));
}
if let Some(ref redir_index) = self.index {
if self.redirect_to_slash && !req.path().ends_with('/') {
let redirect_to = format!("{}/", req.path());
return Box::pin(ok(req.into_response(
HttpResponse::Found()
.insert_header((header::LOCATION, redirect_to))
.finish(),
)));
}
let path = path.join(redir_index);
match NamedFile::open(path) {