| cgi-3001.1.6.0: A library for writing CGI programs | Source code | Contents | Index

Network.CGI.Monad

Portability | non-portable
Stability | experimental
Maintainer | bjorn@bringert.net

Contents

CGI monad class
CGI monad transformer
Request info
Error handling

Description
Internal stuff that most people shouldn't have to use. This module mostly deals with the internals of the CGIT monad transformer.
Synopsis

class Monad m => MonadCGI m where

cgiAddHeader :: HeaderName -> String -> m ()
cgiGet :: (CGIRequest -> a) -> m a

newtype CGIT m a = CGIT {

unCGIT :: (ReaderT CGIRequest (WriterT Headers m) a)

}

type CGI a = CGIT IO a
runCGIT :: Monad m => CGIT m a -> CGIRequest -> m (Headers, a)

data CGIRequest = CGIRequest {

cgiVars :: (Map String String)
cgiInputs :: [(String, Input)]
cgiRequestBody :: ByteString

}

throwCGI :: (MonadCGI m, MonadIO m) => Exception -> m a
catchCGI :: CGI a -> (Exception -> CGI a) -> CGI a
tryCGI :: CGI a -> CGI (Either Exception a)
handleExceptionCGI :: CGI a -> (Exception -> CGI a) -> CGI a

CGI monad class

class Monad m => MonadCGI m where | Source

The class of CGI monads. Most CGI actions can be run in any monad which is an instance of this class, which means that you can use your own monad transformers to add extra functionality.
Methods

cgiAddHeader :: HeaderName -> String -> m () | Source

Add a response header.

cgiGet :: (CGIRequest -> a) -> m a | Source

Get something from the CGI request.

Instances

Monad m => MonadCGI (CGIT m)

CGI monad transformer

newtype CGIT m a | Source

The CGIT monad transformer.
Constructors

CGIT |

unCGIT :: (ReaderT CGIRequest (WriterT Headers m) a) |

Instances

MonadTrans CGIT
MonadError Exception (CGIT IO)
Monad m => Functor (CGIT m)
Monad m => Monad (CGIT m)
Monad m => MonadCGI (CGIT m)
MonadIO m => MonadIO (CGIT m)
(Typeable1 m, Typeable a) => Typeable (CGIT m a)

type CGI a = CGIT IO a | Source

A simple CGI monad with just IO.

runCGIT :: Monad m => CGIT m a -> CGIRequest -> m (Headers, a) | Source

Run a CGI action.
Request info

data CGIRequest | Source

The input to a CGI action.
Constructors

CGIRequest |

cgiVars :: (Map String String) | Environment variables.
cgiInputs :: [(String, Input)] | Input parameters. For better laziness in reading inputs, this is not a Map.
cgiRequestBody :: ByteString | Raw request body. To avoid memory leaks, this is the empty string if the request body has been interpreted as inputs in application/x-www-form-urlencoded or multipart/form-data format.

Instances

Show CGIRequest

Error handling

throwCGI :: (MonadCGI m, MonadIO m) => Exception -> m a | Source

Throw an exception in a CGI monad. The monad is required to be a `MonadIO`, so that we can use `throwIO` to guarantee ordering.

catchCGI :: CGI a -> (Exception -> CGI a) -> CGI a | Source

Catches any expection thrown by a CGI action, and uses the given exception handler if an exception is thrown.

tryCGI :: CGI a -> CGI (Either Exception a) | Source

Catches any exception thrown by an CGI action, and returns either the exception, or if no exception was raised, the result of the action.

handleExceptionCGI :: CGI a -> (Exception -> CGI a) -> CGI a | Source

Deprecated version of `catchCGI`. Use `catchCGI` instead.
Produced by Haddock version 0.9