Skip to content

Commit d558bc7

Browse files
authored
Merge pull request #818 from Julow/remove-option-lwt
Remove uses of Ocsigen_lib Option.Lwt and Dlist.lwt_fold
2 parents 27a7eb7 + 5e5b01b commit d558bc7

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/lib/eliom_state.server.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,11 @@ module Ext = struct
13611361
let a = fold_sub_states_aux_aux ?sitedata ~state:state' f in
13621362
fold_sub_states_aux Ocsigen_cache.Dlist.fold Ocsigen_lib.id a e state
13631363

1364+
(** Fold over the snapshot of a Dlist. *)
1365+
let dlist_lwt_fold f acc dlist =
1366+
Ocsigen_cache.Dlist.fold (fun acc x -> x :: acc) [] dlist
1367+
|> List.rev |> Lwt_list.fold_left_s f acc
1368+
13641369
let fold_sub_states ?sitedata ~state f e =
13651370
let ((sitedata, sub_states_level, id, f) as a) =
13661371
fold_sub_states_aux_aux ?sitedata ~state f
@@ -1373,7 +1378,7 @@ module Ext = struct
13731378
(Eliom_common.get_site_dir_string sitedata)
13741379
(Some id))
13751380
>>= fun l -> Lwt_list.fold_left_s f e l
1376-
| _ -> fold_sub_states_aux Ocsigen_cache.Dlist.lwt_fold Lwt.return a e state
1381+
| _ -> fold_sub_states_aux dlist_lwt_fold Lwt.return a e state
13771382

13781383
let iter_volatile_sub_states ?sitedata ~state f =
13791384
fold_volatile_sub_states ?sitedata ~state (fun () -> f) ()

src/lib/server/eliommod_cookies.ml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,29 @@ module Persistent_cookies = struct
8989
else Some (cookies_str ^ "," ^ cookie)
9090

9191
let remove_cookie exp_o cookie =
92-
exp_o
93-
|> Eliom_lib.Option.Lwt.iter @@ fun exp ->
94-
modify_opt exp @@ function
95-
| None -> None
96-
| Some cookies_str ->
97-
let cookies = String.split_on_char ',' cookies_str in
98-
let cookies' = List.filter (fun c -> c <> cookie) cookies in
99-
if cookies' = [] then None else Some (String.concat "," cookies')
92+
match exp_o with
93+
| None -> Lwt.return_unit
94+
| Some exp -> (
95+
modify_opt exp @@ function
96+
| None -> None
97+
| Some cookies_str ->
98+
let cookies = String.split_on_char ',' cookies_str in
99+
let cookies' = List.filter (fun c -> c <> cookie) cookies in
100+
if cookies' = [] then None else Some (String.concat "," cookies'))
100101
end
101102

102103
let add cookie ({expiry; _} as content) =
103-
Eliom_lib.Option.Lwt.iter (fun t -> Expiry_dates.add_cookie t cookie) expiry
104-
>>= fun _ -> Cookies.add cookie content
104+
match expiry with
105+
| Some t ->
106+
Expiry_dates.add_cookie t cookie >>= fun _ -> Cookies.add cookie content
107+
| None -> Lwt.return_unit
105108

106109
let replace_if_exists cookie ({expiry; _} as content) =
107-
Eliom_lib.Option.Lwt.iter (fun t -> Expiry_dates.add_cookie t cookie) expiry
108-
>>= fun _ -> Cookies.replace_if_exists cookie content
110+
match expiry with
111+
| Some t ->
112+
Expiry_dates.add_cookie t cookie >>= fun _ ->
113+
Cookies.replace_if_exists cookie content
114+
| None -> Lwt.return_unit
109115

110116
let garbage_collect ~section gc_cookie =
111117
let now = Unix.time () in

0 commit comments

Comments
 (0)