Network.CGI.Monad

cgi-3001.2.2.2: A library for writing CGI programs

Copyright | (c) Bjorn Bringert 2006
License | BSD-style
Maintainer | John Chee <cheecheeo@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | None
Language | Haskell98

Network.CGI.Monad

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, MonadThrow m) => SomeException -> m a
- catchCGI :: (MonadCGI m, MonadCatch m) => m a -> (SomeException -> m a) -> m a
- tryCGI :: (Functor m, MonadCGI m, MonadCatch m) => m a -> m (Either SomeException a)
- handleExceptionCGI :: (MonadCGI m, MonadCatch m) => m a -> (SomeException -> m a) -> m a

# CGI monad class

class Monad m => MonadCGI m where

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 ()

Add a response header.

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

Get something from the CGI request.

Instances

Monad m => MonadCGI (CGIT m) |

# CGI monad transformer

newtype CGIT m a

The CGIT monad transformer.

Constructors

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

Instances

MonadTrans CGIT |
MonadCatch m => MonadError SomeException (CGIT m) |
Monad m => Monad (CGIT m) |
(Functor m, Monad m) => Functor (CGIT m) |
(Applicative m, Monad m) => Applicative (CGIT m) |
MonadThrow m => MonadThrow (CGIT m) |
MonadCatch m => MonadCatch (CGIT m) |
MonadMask m => MonadMask (CGIT m) |
MonadIO m => MonadIO (CGIT m) |
Monad m => MonadCGI (CGIT m) |

type CGI a = CGIT IO a

A simple CGI monad with just IO.

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

Run a CGI action.

# Request info

data CGIRequest

The input to a CGI action.

Constructors

CGIRequest |
Fields 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, MonadThrow m) => SomeException -> m a

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

catchCGI :: (MonadCGI m, MonadCatch m) => m a -> (SomeException -> m a) -> m a

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

tryCGI :: (Functor m, MonadCGI m, MonadCatch m) => m a -> m (Either SomeException a)

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 :: (MonadCGI m, MonadCatch m) => m a -> (SomeException -> m a) -> m a

Deprecated: Use catchCGI instead.

Deprecated version of `catchCGI`. Use `catchCGI` instead.