Outdated egg!

This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.


http-session is an implementation of facilities for managing HTTP sessions of web applications.


Mario Domenech Goulart




http, sha1

Parameters and procedures


'''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.


Web server

  (use spiffy web-scheme-handler web-scheme http-session)
  (spiffy-file-ext-handlers `(("ws" . ,web-scheme-handler)))


(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))))

Version History

added http-session:bindings, bug fix for http-session:set!.
bug fix
initial release