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

Tidy up flash message cookies. #137

Merged
merged 3 commits into from
Jul 20, 2021
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
9 changes: 7 additions & 2 deletions src/middleware/flash.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ let flash_messages inner_handler request =
let request = Dream.with_local storage outbox request in
let%lwt response = inner_handler request in
let entries = List.rev !outbox in
let existing = Dream.cookie flash_cookie request in
let resp = match existing, entries with
| None, [] -> response
| Some _, [] -> Dream.set_cookie flash_cookie "" request response ~expires:0.
| _, _ ->
let content =
List.fold_right (fun (x,y) a -> `String x :: `String y :: a) entries [] in
let value = `List content |> Yojson.Basic.to_string in
Dream.set_cookie flash_cookie value request response ~max_age:five_minutes
|> Lwt.return

in
Lwt.return resp


let (|>?) =
Expand Down