Sessions

A functional web interface needs to be able to treat each person accessing the site as an individual. The way this works out in practice is by associating a “session” with each user, through the use of a single cookie on the client machine referencing that particular user’s data stored on the web server. There are other less secure and less practical ways of acomplishing this, but experience has led the world to accept this as standard.

Session Types and Plugins

Within that standard, however, a number of variations have developed on the actual implementation. Arrow comes standard with a couple of these, as well as offering an easily configured plugin architecture for implementing any of the others.

The Arrow configuration file has a section on sessions, wherein you can decide how sessions should behave.

   1  session: 
   2    lockType: recommended
   3    storeType: file:/tmp/sessions
   4    idType: md5:.
   5    idName: session
   6    rewriteUrls: false
Session configuration
expires
This sets the default length of time that a session will remain active without use.
idType
The URI of the type of session id to use.
storeType
The URI of the type of session store to use.
lockType
The URI of the type of lock to use. If it is set to 'recommended', the session store’s recommended lock is used.
rewriteUrls
Rewrite URLs in links in outgoing content to include the session key.
idName
The name of the cookie/parameter that contains the session key.

Session Application – Counter

Beyond the initial configuration, Arrow makes using sessions transparent and natural. The session interface is set up automatically inside your applets – you need only treat it as a user-specific hash, accessing and altering data like normal.

   1  def_action :counter do |txn|
   2      txn.session["accesses"] ||= 0
   3      txn.session["accesses"] += 1
   4      return <<-EOF
   5      <html>
   6        <head><title>Counter</title></head>
   7        <body>
   8          <p>I've seen you #{txn.session["accesses"]} times!</p>
   9        </body>
  10      </html>
  11      EOF
  12    end
  13  # ~> -:2: undefined method `def_action' for main:Object (NoMethodError)