Skip to content
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

Drop extra slashes #866

Merged
merged 2 commits into from
Feb 20, 2023
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
16 changes: 9 additions & 7 deletions src/ocamlorg_web/lib/middleware.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
let no_trailing_slash next_handler request =
let target = Dream.target request in
match target with
| "/" -> next_handler request
| _ ->
if String.ends_with ~suffix:"/" target then
Dream.redirect request (String.sub target 0 (String.length target - 1))
else next_handler request
let target = "///" ^ Dream.target request in
(* FIXME: https://github.com/aantron/dream/issues/248 *)
let path, query = target |> Dream.split_target in
let path =
path |> Dream.from_path |> Dream.drop_trailing_slash |> Dream.to_path
in
let target = path ^ if query = "" then "" else "?" ^ query in
if Dream.target request = target then next_handler request
else Dream.redirect request target

let head handler request =
match Dream.method_ request with
Expand Down