8000 fs: Simplify maybe_redirect_or_append_path by jplatte · Pull Request #440 · tower-rs/tower-http · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fs: Simplify maybe_redirect_or_append_path #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions tower-http/src/services/fs/serve_dir/open_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,21 @@ async fn maybe_redirect_or_append_path(
uri: &Uri,
append_index_html_on_directories: bool,
) -> Option<OpenFileOutput> {
if !uri.path().ends_with('/') {
if is_dir(path_to_file).await {
if append_index_html_on_directories {
let location =
HeaderValue::from_str(&append_ 8A8E slash_on_path(uri.clone()).to_string()).unwrap();
Some(OpenFileOutput::Redirect { location })
} else {
Some(OpenFileOutput::FileNotFound)
}
} else {
None
}
} else if is_dir(path_to_file).await {
if append_index_html_on_directories {
path_to_file.push("index.html");
None
} else {
Some(OpenFileOutput::FileNotFound)
}
} else {
if !is_dir(path_to_file).await {
return None;
}

if !append_index_html_on_directories {
return Some(OpenFileOutput::FileNotFound);
}

if uri.path().ends_with('/') {
path_to_file.push("index.html");
None
} else {
let location =
HeaderValue::from_str(&append_slash_on_path(uri.clone()).to_string()).unwrap();
Some(OpenFileOutput::Redirect { location })
}
}

Expand Down
0