cgi-3001.5.1.0: 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 | Haskell2010

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 :: Type -> Type) where
  - cgiAddHeader :: HeaderName -> String -> m ()
  - cgiGet :: (CGIRequest -> a) -> m a
- newtype CGIT (m :: Type -> Type) 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 :: MonadThrow m => SomeException -> m a
- catchCGI :: MonadCatch m => m a -> (SomeException -> m a) -> m a
- tryCGI :: MonadCatch m => m a -> m (Either SomeException a)
- handleExceptionCGI :: MonadCatch m => m a -> (SomeException -> m a) -> m a

# CGI monad class

class Monad m => MonadCGI (m :: Type -> Type) 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

Instances details

Monad m => MonadCGI (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods cgiAddHeader :: HeaderName -> String -> CGIT m () Source # cgiGet :: (CGIRequest -> a) -> CGIT m a Source #

# CGI monad transformer

newtype CGIT (m :: Type -> Type) a Source #

The CGIT monad transformer.

Constructors

CGIT |

Fields

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

#### Instances

Instances details

MonadTrans CGIT Source # |
Instance details Defined in Network.CGI.Monad Methods lift :: Monad m => m a -> CGIT m a Source #
MonadCatch m => MonadError SomeException (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods throwError :: SomeException -> CGIT m a Source # catchError :: CGIT m a -> (SomeException -> CGIT m a) -> CGIT m a Source #
MonadIO m => MonadIO (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods liftIO :: IO a -> CGIT m a Source #
Monad m => MonadCGI (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods cgiAddHeader :: HeaderName -> String -> CGIT m () Source # cgiGet :: (CGIRequest -> a) -> CGIT m a Source #
MonadCatch m => MonadCatch (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods catch :: (HasCallStack, Exception e) => CGIT m a -> (e -> CGIT m a) -> CGIT m a Source #
MonadMask m => MonadMask (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods mask :: HasCallStack => ((forall a. CGIT m a -> CGIT m a) -> CGIT m b) -> CGIT m b Source # uninterruptibleMask :: HasCallStack => ((forall a. CGIT m a -> CGIT m a) -> CGIT m b) -> CGIT m b Source # generalBracket :: HasCallStack => CGIT m a -> (a -> ExitCase b -> CGIT m c) -> (a -> CGIT m b) -> CGIT m (b, c) Source #
MonadThrow m => MonadThrow (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods throwM :: (HasCallStack, Exception e) => e -> CGIT m a Source #
Applicative m => Applicative (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods pure :: a -> CGIT m a Source # (<*>) :: CGIT m (a -> b) -> CGIT m a -> CGIT m b Source # liftA2 :: (a -> b -> c) -> CGIT m a -> CGIT m b -> CGIT m c Source # (*>) :: CGIT m a -> CGIT m b -> CGIT m b Source # (<*) :: CGIT m a -> CGIT m b -> CGIT m a Source #
Functor m => Functor (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods fmap :: (a -> b) -> CGIT m a -> CGIT m b Source # (<$) :: a -> CGIT m b -> CGIT m a Source #
Monad m => Monad (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods (>>=) :: CGIT m a -> (a -> CGIT m b) -> CGIT m b Source # (>>) :: CGIT m a -> CGIT m b -> CGIT m b Source # return :: a -> CGIT m a Source #
MonadFail m => MonadFail (CGIT m) Source # |
Instance details Defined in Network.CGI.Monad Methods fail :: String -> CGIT m a Source #

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 |

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

Instances details

Show CGIRequest Source # |
Instance details Defined in Network.CGI.Protocol Methods showsPrec :: Int -> CGIRequest -> ShowS Source # show :: CGIRequest -> String Source # showList :: [CGIRequest] -> ShowS Source #

# Error handling

throwCGI :: MonadThrow m => SomeException -> m a Source #

Deprecated: Use Control.Monad.Catch.throwM instead.

Deprecated alias for `throwM`. Please use `throwM` instead.

catchCGI :: MonadCatch m => m a -> (SomeException -> m a) -> m a Source #

Deprecated: Use Control.Monad.Catch.catch instead.

Deprecated alias for `catch`. Please use `catch` instead.

tryCGI :: MonadCatch m => m a -> m (Either SomeException a) Source #

Deprecated: Use Control.Monad.Catch.try instead.

Deprecated alias for `try`. Please use `try` instead.

handleExceptionCGI :: MonadCatch m => m a -> (SomeException -> m a) -> m a Source #

Deprecated: Use Control.Monad.Catch.catch instead.

Deprecated alias for `catch`. Please use `catch` instead.