Skip to content

Commit

Permalink
avoid folder redirects for .SQL files (in capital letters)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Jul 26, 2023
1 parent 18cdb63 commit a9b41ad
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/webserver/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,11 @@ fn req_path(req: &ServiceRequest) -> Cow<'_, str> {

fn redirect_missing_trailing_slash(uri: &Uri) -> Option<HttpResponse> {
let path = uri.path();
if !path.ends_with('/') && !path.ends_with(".sql") {
if !path.ends_with('/')
&& !path
.rsplit_once('.')
.is_some_and(|(_, ext)| ext.eq_ignore_ascii_case("sql"))
{
let mut redirect_path = path.to_owned();
redirect_path.push('/');
if let Some(query) = uri.query() {
Expand All @@ -485,8 +489,7 @@ fn redirect_missing_trailing_slash(uri: &Uri) -> Option<HttpResponse> {
Some(
HttpResponse::MovedPermanently()
.insert_header((header::LOCATION, redirect_path))
.finish()
.into(),
.finish(),
)
} else {
None
Expand Down

0 comments on commit a9b41ad

Please sign in to comment.