public
Description: Concise web framework for Clojure
Home | Edit | New

Sessions

Compojure sessions are managed by the with-session middleware defined in compojure.http.session. When a handler is decorated with the with-session middleware, sessions are associated with the request, and can be updated via the response. Multi-methods are used to define an interface used to store and retrieve session data, and this interface can be used to support a wide range of session storage options.

The with-session middleware works as follows:

A session is read from the session data stored in the “compojure-session” cookie, by use of (read-session session-data). If the session does not exist, the session is created with (create-session).

The session is then associated with the :session key on the request, and the request is passed to the handler. The handler returns a response. If the response contains a :session key, or if the session is newly created, the session is saved with (write-session session).

Before the handler response is returned, (set-session-cookie session) is called. If the return value is not nil, the value is added to a cookie on the response called “compojure-session”. The response is then returned from the middleware.

Last edited by weavejester, Thu May 14 13:24:58 -0700 2009
Home | Edit | New
Versions: