Simple_httpd.SessionSourceModule to handle session data
This module allows to manage sessions which are common to several clients and can survive a deconnection of the clients. This does not provide any form of authentication, but it is easy to use them to implement authentication.
It is recommended to create session only for authenticated connection: sessions require some memory (around 100 bytes) on the server, and if you have a session life time of one hour, an attaquant could exhaust available memory. Unauthenticated session with a short life comparable to the connection timeout could be acceseptable, as clients also uses some memory.
type for session
session can hold several values of arbitrary type associated to a key The type of key is an extensible variant that you can extend to hold some data which resides in the server memory. These data will be lost if the server reboots.
Possible uses are
val new_key :
?cleanup_delete:('a -> unit) ->
?cleanup_no_client:('a -> bool) ->
?save:(out_channel -> 'a -> unit) ->
?load:(in_channel -> 'a) ->
string ->
'a keynew_key () creates a new key, to associate data.
The optional argument cleanup_delete is called when the session is deleted.
The optional argument cleanup_no_client is clalled when no more client are connected to that session or when the session is deleted. If it returns false, the data is deleted, otherwise, it is kept.
cleanup_delete is called if and only if cleanup_no_client returns true.
element of this type control the managment of cookies
value is { path = "/" ; base = "Session"; ; life = 3600.0 ; filter = fun _ -> None }
val start_check :
?create:bool ->
?check:(t -> bool) ->
?cookie_policy:cookie_policy ->
?nosession:exn ->
?error:(Response_code.t * Headers.t) ->
'a Request.t ->
Cookies.t * tCheck or create a new session and add the session cookies to the cookie of the request. This can fail if
If it fails, all cookies in the request are expired by the resposne sent.
val filter :
?check:(t -> bool) ->
?cookie_policy:cookie_policy ->
?error:(Response_code.t * Headers.t) ->
'a Filter.tSame as above as a filter. The cookies are added to the response.
get the client session is any. No check is performed on the session cookie
get the session data associated to the given key from a session. raises Not_found if the key is not present
update or add the session data associated to the givent key
remove the session data associated to the givent key
remove all server side and client side session data by expiring the session cookies.