[Haskell-cafe] Application Level server state in Haskell Web server

Pieter Laeremans pieter at laeremans.org
Sat Feb 17 21:09:06 EST 2007


Hello,

I'm trying to write a simple module for the haskell web server (hws- 
cgi).

And I would like to write a simple module that maintains some kind of  
state for a session.

But I'm I write I cannot do this in pure Haskell ? Without adopting  
the sources of the Haskell web server ?

I'll examplify to make it more concrete :

The requestHandler function a module has to implement has this  
signature.

requestHandler :: ServerState -> ServerRequest  -> IO (Maybe Response)

Let 's assume I have this implementation

requestHandler st _ = return $ Just  $ mkRequest
     where mkRequest =
               okResponse (serverConfig st) mkBody hs True
           mkBody = HereItIs " This is a test"
           hs = mkHeaders [contentTypeHeader "text/html"]

And I would like the response to include, for example,  a number  
indicating the number of calls that has been handled by the module.

I would concider using an Mvar but I can't "remember"  the mvar  
between requests.

Am I right to assume  that the interface of the requestHandler method  
has to be adapted ?  Or that serverstate has to be adopted so that it  
can act as a datastore ?

kind regards,

Pieter


More information about the Haskell-Cafe mailing list