hsp-0.2: HSP/Data/Response.hs
-----------------------------------------------------------------------------
-- |
-- Module : HSP.Data.Response
-- Copyright : (c) Niklas Broberg 2004,
-- License : BSD-style (see the file LICENSE.txt)
--
-- Maintainer : Niklas Broberg, d00nibro@dtek.chalmers.se
-- Stability : experimental
-- Portability : requires undecidable and overlapping instances
--
-- Defines the Response object available to HSP pages.
-----------------------------------------------------------------------------
module HSP.Data.Response (
Response -- ^ The Response type is abstract
, initResponse -- ^ :: IO Response
, setOutgoingHeader -- ^ :: Response -> String -> String -> IO ()
, getHeaders -- ^ :: Response -> IO [(String, String)]
) where
import Data.IORef
data Response = Response {
outHeaders :: IORef [(String, String)]
}
-- | Set a header in the outgoing response.
setOutgoingHeader :: Response -> String -> String -> IO ()
setOutgoingHeader resp hdn hdv =
modifyIORef (outHeaders resp) ((hdn,hdv):)
-- | Initialise a blank response.
initResponse = do ref <- newIORef []
return $ Response { outHeaders = ref }
-- | Get all set headers.
getHeaders :: Response -> IO [(String, String)]
getHeaders = readIORef . outHeaders