Module Session_cohttp_async.Make
Create an Async-based session manager given a compatible backend.
Parameters
B : Session_cookie.Backend with type +'a B.io = 'a Async_kernel.Deferred.t
Signature
type +'a io= 'a Async_kernel.Deferred.tThe type of a blocking computation that will produce a value of type
'a
type backend= B.tThe type of a handle on the store.
type t= private{key : key;They key for the session in the backend and in cookies.
mutable value : value;The value for the session stored in the backend.
mutable expiry_period : period;The period from now in seconds that the session will expire.
mutable modified : bool;Whether the session data or expiry have been modified
}The session type.
This type is marked private, so the record fields can be accessed and pattern-matched as usual. However, values of this type cannot be constructed directly. To create a new session, use
generate. To retrieve an existingsession, useof_keyorof_header. To modifyt.expiry_periodort.value, useset. Finally, useto_cookie_hdrsto smartly generateSet-Cookieand related headers.
val of_key : backend -> key -> (t, Session.S.error) Stdlib.result ioof_key backend keyfetches the session associated withkeyfrom the backend, if present and unexpired.
val of_header : backend -> string -> Cookie.header -> (t option, Session.S.error) Stdlib.result ioof_header backend cookie_key headerretrieves the session key from the cookies inheader. Ifcookie_keyis not present in any cookies inheader, then this function will returnNone. If a session key is found, it will call{!val:of_key} backend key. If both lookups were successful, then this function will returnSome session. If no key was found inheader, it will returnNone.
val of_header_or_create : ?expiry:period -> backend -> string -> value -> Cookie.header -> t ioof_header_or_create ?expiry backend cookie_key default headerretrieves the session key from the cookies inheader. Ifcookie_keyis not present in any cookies in theheaderor if the session is not a valid one, a new session will be usingexpiryfor the expiration period anddefaultas the value.
val to_cookie_hdrs : ?discard:bool -> ?path:string -> ?domain:string -> ?secure:bool -> ?http_only:bool -> string -> t -> (string * string) listto_cookie_hdrs cookie_key sessionwill generate response headers to communicate session changes to the client. This function takes into account thet.modifiedfield of the session type, and will not generate headers if they are not needed.
val clear_hdrs : ?path:string -> ?domain:string -> string -> (string * string) listclear_hdrs cookie_keywill generate response headers to communicate that the client should evict the session with keycookie_key.
val generate : ?expiry:period -> backend -> value -> t iogenerate ?expiry backend valuewill allocate a new session in the backendbackend. The session will expireexpiryseconds from now, defaulting todefault_period backendif one is not explicitly specified.
val clear : backend -> t -> unit ioclear backend sessionremovessessionfrombackend. The backend may choose to persist the session value beyond this call, but any subsequent operations involvingkeyshould behave as ifkeyis not present in the backend.The
valueandt.expiry_periodofsessionwill be zero'd out, and thet.modifiedflag will be set. Callingto_cookie_hdrson a cleared session will generate the appropriate headers directing the client to clear the associated cookie.
val set : ?expiry:period -> ?value:value -> backend -> t -> unit ioset ?expiry ?value backend sessionsets thevaluefor the session associatedkeyinbackendand sets the session to expireexpiryseconds from now. Ifexpiryis not provided, the expiry period reported bydefault_period backendwill be used instead. If no value is provided, then only the expiry will be updated.