Hcs.Plug.Session
hcs · API reference
Cookie-based session management with fiber-local isolation.
let store = Session.Memory_store.create () in
let session_plug = Session.create ~store () in
let handler req =
match Session.get "user_id" with
| Some uid -> Session.put "last_seen" (string_of_float now); ...
| None -> ...type session = {
id : string;
data : (string * string) list;
created_at : float;
}type store =
| Memory of (string, session) Kcas_data.Hashtbl.t
| Cookie of {
secret : string;
max_age : float;
}type session_ctx = {
mutable data : (string * string) list;
mutable modified : bool;
}val session_key : session_ctx Eio.Fiber.keyval get_ctx : unit -> session_ctxmodule Memory_store : sig ... endmodule Cookie_store : sig ... endval get : string -> string optionval get_with_req : 'a -> string -> string optionval put : string -> string -> unitval put_with_req : 'a -> string -> string -> unitval delete : string -> unitval delete_with_req : 'a -> string -> unitval clear : unit -> unitval clear_with_req : 'a -> unitval get_all : unit -> (string * string) listval get_all_with_req : 'a -> (string * string) listtype config = {
cookie_name : string;
store : store;
secure : bool;
same_site : [ `Strict | `Lax | `None ];
http_only : bool;
path : string;
max_age : float;
}val parse_cookie :
cookie_name:string ->
(string * string) list ->
string optionval make_cookie : config:config -> string -> stringval generate_id : unit -> stringval create :
store:store ->
?cookie_name:string ->
?secure:bool ->
?same_site:[ `Lax | `None | `Strict ] ->
?http_only:bool ->
?path:string ->
?max_age:float ->
unit ->
(Server.request -> Server.response) ->
Server.request ->
Server.responseCreate session plug with configurable storage and cookie options.