cgi-utils-0.2.1: Simple modular utilities for CGI/FastCGI (sessions, etc.)




Example usage:

 module Main where
 import Data.Maybe
 import Network.CGI
 import Network.CGI.Session
 import Network.FastCGI
 main = do
   runSessionCGI "myapp" runFastCGI $ do
     n <- fmap (fromMaybe 0) $ sessionGet "age"
     sessionIns "age" 1 (+)
     output $ show n ++ " visits to this page."



data Session Source

A session consists of a unique id and a map.



type Sessions = MVar ([Integer], Map Integer Session)Source

Sessions and unique ids are stored in an MVar.

type SessionName = StringSource

The cookie prefix (e.g. MYHASKELLCOOKIE).

type SessionM = StateT Session (CGIT IO)Source

A simple Session monad. Recommend you define your own.

Initialising and querying/updating

makeSessions :: IO SessionsSource

Make the sessions state.

initSession :: SessionName -> Sessions -> CGI SessionSource

Grab the session or create a new one.

updateSession :: Sessions -> Session -> CGI ()Source

Update a session in the map.

sessionId :: SessionM IntegerSource

Session value getter.

A simple Session monad.

runSessionCGI :: SessionName -> (CGI CGIResult -> IO ()) -> SessionM CGIResult -> IO ()Source

Initialise a session state and start a F/CGI process. This is a bit of a pattern so I've included it here for convenience.

runSession :: Sessions -> SessionM a -> Session -> CGI aSource

Simple session runner.

sessionIns :: (Read a, Show a) => String -> a -> (a -> a -> a) -> SessionM ()Source

Session value inserter/updater.

sessionDel :: String -> SessionM ()Source

Session value deleter.

sessionGet :: Read a => String -> SessionM (Maybe a)Source

Session value getter.


makeSession :: SessionName -> Sessions -> CGI SessionSource

Create a new session and update the Mvar.

getSession :: SessionName -> Sessions -> CGI (Maybe Session)Source

Try to get the current session.