Note: This is taken from the Chicken Wiki, where a more recent version could be available.
http-session is an implementation of facilities for managing HTTP sessions of web applications.
Mario Domenech Goulart
BSD
parameter: http-session:table
The session table. The default value returns an empty session table (first invocation) or the currently session table (subsequent invocations).
parameter: http-session:lifetime
The lifetime of sessions in seconds. Default is 3600s (1h).
parameter: http-session:id-generator
A zero argument procedure which generates a random unique identifier for sessions.
procedure: (http-session:create url-pattern #!optional bindings)
Creates a session and returns the session identifier. The URL-PATTERN argument is a regular expression used to match accessed pathnames against pathnames from the web server's root directory.
The optional BINDINGS argument is an alist '((symbol . value)...) of variable bindings valid for the generated session.
procedure: (http-session:refresh! sid)
Refreshes the session identified by SID, that is, sets the lifetime of the session identified by SID to (http-session:lifetime).
procedure: (http-session:valid? sid)
Returns #t if the session identified by SID is valid. Returns #f otherwise.
A session is valid if (all items should be satisfied):
procedure: (http-session:delete! sid)
Deletes the session identified by SID.
procedure: (http-session:ref sid var #!optional default)
Returns the value corresponding to VAR from the bindings alist of the session identified by SID. If the binding does not exist, DEFAULT is returned.
procedure: (http-session:set! sid var val)
Sets a value VAL for the VAR symbol in the bindings alist for the session identified by SID. If the symbol does not exist in the bindings alist, it is added to it.
procedure: (http-session:delete-binding! sid var)
Deletes the VAR symbol and its corresponding value from the bindings alist of the session identified by SID.
procedure: (http-session:bindings sid)
Returns an alist '((variable . value) ... ) representing the bindings of the session identified by SID.
(use spiffy web-scheme-handler web-scheme http-session) (spiffy-file-ext-handlers `(("ws" . ,web-scheme-handler))) (start-server)
(define (page:next sid) (ws:page (string-append (h1 (let ((n (add1 (http-session:ref sid 'n 0)))) (http-session:set! sid 'n n) (number->string n))) (a 'href (string-append "?sid=" sid) "Next")))) (ws:with-get-vars (sid) (if sid (if (http-session:valid? sid) (begin (http-session:refresh! sid) (page:next sid)) (ws:page "Invalid session.")) (let ((sid (http-session:create "/.*"))) (page:next sid))))