    {-# LANGUAGE MultiParamTypeClasses #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Network.CGI.Monad
    -- Copyright   :  (c) Bjorn Bringert 2006
    -- License     :  BSD-style
    --
    -- Maintainer  :  John Chee <cheecheeo@gmail.com>
    -- Stability   :  experimental
    -- Portability :  non-portable
    --
    -- Internal stuff that most people shouldn't have to use.
    -- This module mostly deals with the
    -- internals of the CGIT monad transformer.
    --
    -----------------------------------------------------------------------------

    module Network.CGI.Monad (
      -- * CGI monad class
      MonadCGI(..),
      -- * CGI monad transformer
      CGIT(..), CGI,
      runCGIT,
      -- * Request info
      CGIRequest(..),
      -- * Error handling
      throwCGI, catchCGI, tryCGI, handleExceptionCGI,
     ) where

    import Prelude hiding ( fail )

    import Control.Exception as Exception (SomeException)
    import Control.Applicative (Applicative(..))
    import Control.Monad.Catch (MonadCatch, MonadThrow, MonadMask, throwM, catch, try, mask, uninterruptibleMask, generalBracket)
    import Control.Monad.Except (MonadError(..))
    import Control.Monad.Reader (ReaderT(..), asks)
    import Control.Monad.Writer (WriterT(..), tell)
    import Control.Monad.Fail (MonadFail(..))
    import Control.Monad.Trans (MonadTrans, MonadIO, liftIO, lift)
    import Network.CGI.Protocol

    --
    -- * CGIT monad transformer
    --

    -- | A simple CGI monad with just IO.
    type CGI a = CGIT IO a

    -- | The CGIT monad transformer.
    newtype CGIT m a = CGIT { forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT :: ReaderT CGIRequest (WriterT Headers m) a }

    instance (Functor m) => Functor (CGIT m) where
        fmap :: forall a b. (a -> b) -> CGIT m a -> CGIT m b
    fmap a -> b
    f CGIT m a
    c = ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT ((a -> b)
    -> ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall a b.
    (a -> b)
    -> ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> b
    f (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT CGIT m a
    c))

    instance (Applicative m) => Applicative (CGIT m) where
        pure :: forall a. a -> CGIT m a
    pure = ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> (a -> ReaderT CGIRequest (WriterT Headers m) a) -> a -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> ReaderT CGIRequest (WriterT Headers m) a
    forall a. a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure
        CGIT m (a -> b)
    f <*> :: forall a b. CGIT m (a -> b) -> CGIT m a -> CGIT m b
    <*> CGIT m a
    x = ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (CGIT m (a -> b) -> ReaderT CGIRequest (WriterT Headers m) (a -> b)
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT CGIT m (a -> b)
    f ReaderT CGIRequest (WriterT Headers m) (a -> b)
    -> ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall a b.
    ReaderT CGIRequest (WriterT Headers m) (a -> b)
    -> ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT CGIT m a
    x)

    instance Monad m => Monad (CGIT m) where
        CGIT m a
    c >>= :: forall a b. CGIT m a -> (a -> CGIT m b) -> CGIT m b
    >>= a -> CGIT m b
    f = ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT CGIT m a
    c ReaderT CGIRequest (WriterT Headers m) a
    -> (a -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall a b.
    ReaderT CGIRequest (WriterT Headers m) a
    -> (a -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT (CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b)
    -> (a -> CGIT m b) -> a -> ReaderT CGIRequest (WriterT Headers m) b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> CGIT m b
    f)
        return :: forall a. a -> CGIT m a
    return = ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> (a -> ReaderT CGIRequest (WriterT Headers m) a) -> a -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> ReaderT CGIRequest (WriterT Headers m) a
    forall a. a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return

    instance MonadFail m => MonadFail (CGIT m) where
        fail :: forall a. String -> CGIT m a
    fail = ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> (String -> ReaderT CGIRequest (WriterT Headers m) a)
    -> String
    -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> ReaderT CGIRequest (WriterT Headers m) a
    forall a. String -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail

    instance MonadIO m => MonadIO (CGIT m) where
        liftIO :: forall a. IO a -> CGIT m a
    liftIO = m a -> CGIT m a
    forall (m :: * -> *) a. Monad m => m a -> CGIT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> CGIT m a) -> (IO a -> m a) -> IO a -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . IO a -> m a
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO

    instance MonadThrow m => MonadThrow (CGIT m) where
        throwM :: forall e a. (HasCallStack, Exception e) => e -> CGIT m a
    throwM = ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> (e -> ReaderT CGIRequest (WriterT Headers m) a) -> e -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . e -> ReaderT CGIRequest (WriterT Headers m) a
    forall e a.
    (HasCallStack, Exception e) =>
    e -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM

    instance MonadCatch m => MonadCatch (CGIT m) where
        CGIT ReaderT CGIRequest (WriterT Headers m) a
    m catch :: forall e a.
    (HasCallStack, Exception e) =>
    CGIT m a -> (e -> CGIT m a) -> CGIT m a
    `catch` e -> CGIT m a
    h = ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall a b. (a -> b) -> a -> b
    $ ReaderT CGIRequest (WriterT Headers m) a
    m ReaderT CGIRequest (WriterT Headers m) a
    -> (e -> ReaderT CGIRequest (WriterT Headers m) a)
    -> ReaderT CGIRequest (WriterT Headers m) a
    forall e a.
    (HasCallStack, Exception e) =>
    ReaderT CGIRequest (WriterT Headers m) a
    -> (e -> ReaderT CGIRequest (WriterT Headers m) a)
    -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    m a -> (e -> m a) -> m a
    `catch` (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a)
    -> (e -> CGIT m a) -> e -> ReaderT CGIRequest (WriterT Headers m) a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . e -> CGIT m a
    h)

    instance MonadMask m => MonadMask (CGIT m) where
        mask :: forall b.
    HasCallStack =>
    ((forall a. CGIT m a -> CGIT m a) -> CGIT m b) -> CGIT m b
    mask (forall a. CGIT m a -> CGIT m a) -> CGIT m b
    a = ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b)
    -> ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b
    forall a b. (a -> b) -> a -> b
    $ ((forall a.
      ReaderT CGIRequest (WriterT Headers m) a
      -> ReaderT CGIRequest (WriterT Headers m) a)
     -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall b.
    HasCallStack =>
    ((forall a.
      ReaderT CGIRequest (WriterT Headers m) a
      -> ReaderT CGIRequest (WriterT Headers m) a)
     -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. m a -> m a) -> m b) -> m b
    mask (((forall a.
       ReaderT CGIRequest (WriterT Headers m) a
       -> ReaderT CGIRequest (WriterT Headers m) a)
      -> ReaderT CGIRequest (WriterT Headers m) b)
     -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ((forall a.
         ReaderT CGIRequest (WriterT Headers m) a
         -> ReaderT CGIRequest (WriterT Headers m) a)
        -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall a b. (a -> b) -> a -> b
    $ \forall a.
    ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) a
    u -> CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT (CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b)
    -> CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b
    forall a b. (a -> b) -> a -> b
    $ (forall a. CGIT m a -> CGIT m a) -> CGIT m b
    a ((forall a. CGIT m a -> CGIT m a) -> CGIT m b)
    -> (forall a. CGIT m a -> CGIT m a) -> CGIT m b
    forall a b. (a -> b) -> a -> b
    $ ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a)
    -> CGIT m a
    -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) a
    forall a.
    ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) a
    u (ReaderT CGIRequest (WriterT Headers m) a
     -> ReaderT CGIRequest (WriterT Headers m) a)
    -> (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a)
    -> CGIT m a
    -> ReaderT CGIRequest (WriterT Headers m) a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT
        uninterruptibleMask :: forall b.
    HasCallStack =>
    ((forall a. CGIT m a -> CGIT m a) -> CGIT m b) -> CGIT m b
    uninterruptibleMask (forall a. CGIT m a -> CGIT m a) -> CGIT m b
    a = ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b)
    -> ReaderT CGIRequest (WriterT Headers m) b -> CGIT m b
    forall a b. (a -> b) -> a -> b
    $ ((forall a.
      ReaderT CGIRequest (WriterT Headers m) a
      -> ReaderT CGIRequest (WriterT Headers m) a)
     -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall b.
    HasCallStack =>
    ((forall a.
      ReaderT CGIRequest (WriterT Headers m) a
      -> ReaderT CGIRequest (WriterT Headers m) a)
     -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. m a -> m a) -> m b) -> m b
    uninterruptibleMask (((forall a.
       ReaderT CGIRequest (WriterT Headers m) a
       -> ReaderT CGIRequest (WriterT Headers m) a)
      -> ReaderT CGIRequest (WriterT Headers m) b)
     -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ((forall a.
         ReaderT CGIRequest (WriterT Headers m) a
         -> ReaderT CGIRequest (WriterT Headers m) a)
        -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) b
    forall a b. (a -> b) -> a -> b
    $ \forall a.
    ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) a
    u -> CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT (CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b)
    -> CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b
    forall a b. (a -> b) -> a -> b
    $ (forall a. CGIT m a -> CGIT m a) -> CGIT m b
    a ((forall a. CGIT m a -> CGIT m a) -> CGIT m b)
    -> (forall a. CGIT m a -> CGIT m a) -> CGIT m b
    forall a b. (a -> b) -> a -> b
    $ ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a)
    -> CGIT m a
    -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) a
    forall a.
    ReaderT CGIRequest (WriterT Headers m) a
    -> ReaderT CGIRequest (WriterT Headers m) a
    u (ReaderT CGIRequest (WriterT Headers m) a
     -> ReaderT CGIRequest (WriterT Headers m) a)
    -> (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a)
    -> CGIT m a
    -> ReaderT CGIRequest (WriterT Headers m) a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT
        generalBracket :: forall a b c.
    HasCallStack =>
    CGIT m a
    -> (a -> ExitCase b -> CGIT m c)
    -> (a -> CGIT m b)
    -> CGIT m (b, c)
    generalBracket CGIT m a
    acquire a -> ExitCase b -> CGIT m c
    release a -> CGIT m b
    f = ReaderT CGIRequest (WriterT Headers m) (b, c) -> CGIT m (b, c)
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) (b, c) -> CGIT m (b, c))
    -> ReaderT CGIRequest (WriterT Headers m) (b, c) -> CGIT m (b, c)
    forall a b. (a -> b) -> a -> b
    $
          ReaderT CGIRequest (WriterT Headers m) a
    -> (a -> ExitCase b -> ReaderT CGIRequest (WriterT Headers m) c)
    -> (a -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) (b, c)
    forall a b c.
    HasCallStack =>
    ReaderT CGIRequest (WriterT Headers m) a
    -> (a -> ExitCase b -> ReaderT CGIRequest (WriterT Headers m) c)
    -> (a -> ReaderT CGIRequest (WriterT Headers m) b)
    -> ReaderT CGIRequest (WriterT Headers m) (b, c)
    forall (m :: * -> *) a b c.
    (MonadMask m, HasCallStack) =>
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c)
    generalBracket (CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT CGIT m a
    acquire) (\a
    a ExitCase b
    b -> CGIT m c -> ReaderT CGIRequest (WriterT Headers m) c
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT (a -> ExitCase b -> CGIT m c
    release a
    a ExitCase b
    b)) (CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b
    forall (m :: * -> *) a.
    CGIT m a -> ReaderT CGIRequest (WriterT Headers m) a
    unCGIT (CGIT m b -> ReaderT CGIRequest (WriterT Headers m) b)
    -> (a -> CGIT m b) -> a -> ReaderT CGIRequest (WriterT Headers m) b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> CGIT m b
    f)

    instance MonadCatch m => MonadError SomeException (CGIT m) where
        throwError :: forall a. SomeException -> CGIT m a
    throwError = SomeException -> CGIT m a
    forall e a. (HasCallStack, Exception e) => e -> CGIT m a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM
        catchError :: forall a. CGIT m a -> (SomeException -> CGIT m a) -> CGIT m a
    catchError = CGIT m a -> (SomeException -> CGIT m a) -> CGIT m a
    forall e a.
    (HasCallStack, Exception e) =>
    CGIT m a -> (e -> CGIT m a) -> CGIT m a
    forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    m a -> (e -> m a) -> m a
    catch

    -- | 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.
    class Monad m => MonadCGI m where
        -- | Add a response header.
        cgiAddHeader :: HeaderName -> String -> m ()
        -- | Get something from the CGI request.
        cgiGet :: (CGIRequest -> a) -> m a

    instance Monad m => MonadCGI (CGIT m) where
        cgiAddHeader :: HeaderName -> String -> CGIT m ()
    cgiAddHeader HeaderName
    n String
    v = ReaderT CGIRequest (WriterT Headers m) () -> CGIT m ()
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) () -> CGIT m ())
    -> ReaderT CGIRequest (WriterT Headers m) () -> CGIT m ()
    forall a b. (a -> b) -> a -> b
    $ WriterT Headers m () -> ReaderT CGIRequest (WriterT Headers m) ()
    forall (m :: * -> *) a. Monad m => m a -> ReaderT CGIRequest m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (WriterT Headers m () -> ReaderT CGIRequest (WriterT Headers m) ())
    -> WriterT Headers m ()
    -> ReaderT CGIRequest (WriterT Headers m) ()
    forall a b. (a -> b) -> a -> b
    $ Headers -> WriterT Headers m ()
    forall w (m :: * -> *). MonadWriter w m => w -> m ()
    tell [(HeaderName
    n,String
    v)]
        cgiGet :: forall a. (CGIRequest -> a) -> CGIT m a
    cgiGet = ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> ((CGIRequest -> a) -> ReaderT CGIRequest (WriterT Headers m) a)
    -> (CGIRequest -> a)
    -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (CGIRequest -> a) -> ReaderT CGIRequest (WriterT Headers m) a
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks

    instance MonadTrans CGIT where
        lift :: forall (m :: * -> *) a. Monad m => m a -> CGIT m a
    lift = ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    forall (m :: * -> *) a.
    ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a
    CGIT (ReaderT CGIRequest (WriterT Headers m) a -> CGIT m a)
    -> (m a -> ReaderT CGIRequest (WriterT Headers m) a)
    -> m a
    -> CGIT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . WriterT Headers m a -> ReaderT CGIRequest (WriterT Headers m) a
    forall (m :: * -> *) a. Monad m => m a -> ReaderT CGIRequest m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (WriterT Headers m a -> ReaderT CGIRequest (WriterT Headers m) a)
    -> (m a -> WriterT Headers m a)
    -> m a
    -> ReaderT CGIRequest (WriterT Headers m) a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m a -> WriterT Headers m a
    forall (m :: * -> *) a. Monad m => m a -> WriterT Headers m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift

    -- | Run a CGI action.
    runCGIT :: Monad m => CGIT m a -> CGIRequest -> m (Headers, a)
    runCGIT :: forall (m :: * -> *) a.
    Monad m =>
    CGIT m a -> CGIRequest -> m (Headers, a)
    runCGIT (CGIT ReaderT CGIRequest (WriterT Headers m) a
    c) = ((a, Headers) -> (Headers, a)) -> m (a, Headers) -> m (Headers, a)
    forall a b. (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((a -> Headers -> (Headers, a)) -> (a, Headers) -> (Headers, a)
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry ((Headers -> a -> (Headers, a)) -> a -> Headers -> (Headers, a)
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip (,))) (m (a, Headers) -> m (Headers, a))
    -> (CGIRequest -> m (a, Headers)) -> CGIRequest -> m (Headers, a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . WriterT Headers m a -> m (a, Headers)
    forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
    runWriterT (WriterT Headers m a -> m (a, Headers))
    -> (CGIRequest -> WriterT Headers m a)
    -> CGIRequest
    -> m (a, Headers)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT CGIRequest (WriterT Headers m) a
    -> CGIRequest -> WriterT Headers m a
    forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT ReaderT CGIRequest (WriterT Headers m) a
    c

    --
    -- * Deprecated error handling functions.
    --

    {-# DEPRECATED throwCGI "Use Control.Monad.Catch.throwM instead." #-}
    -- | Deprecated alias for 'throwM'. Please use 'throwM' instead.
    throwCGI :: (MonadThrow m) => SomeException -> m a
    throwCGI :: forall (m :: * -> *) a. MonadThrow m => SomeException -> m a
    throwCGI = SomeException -> m a
    forall e a. (HasCallStack, Exception e) => e -> m a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM

    {-# DEPRECATED catchCGI "Use Control.Monad.Catch.catch instead." #-}
    -- | Deprecated alias for 'catch'. Please use 'catch' instead.
    catchCGI :: (MonadCatch m) => m a -> (SomeException -> m a) -> m a
    catchCGI :: forall (m :: * -> *) a.
    MonadCatch m =>
    m a -> (SomeException -> m a) -> m a
    catchCGI = m a -> (SomeException -> m a) -> m a
    forall e a. (HasCallStack, Exception e) => m a -> (e -> m a) -> m a
    forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    m a -> (e -> m a) -> m a
    catch

    {-# DEPRECATED tryCGI "Use Control.Monad.Catch.try instead." #-}
    -- | Deprecated alias for 'try'. Please use 'try' instead.
    tryCGI :: (MonadCatch m) => m a -> m (Either SomeException a)
    tryCGI :: forall (m :: * -> *) a.
    MonadCatch m =>
    m a -> m (Either SomeException a)
    tryCGI = m a -> m (Either SomeException a)
    forall (m :: * -> *) e a.
    (HasCallStack, MonadCatch m, Exception e) =>
    m a -> m (Either e a)
    try

    {-# DEPRECATED handleExceptionCGI "Use Control.Monad.Catch.catch instead." #-}
    -- | Deprecated alias for 'catch'. Please use 'catch' instead.
    handleExceptionCGI :: (MonadCatch m) => m a -> (SomeException -> m a) -> m a
    handleExceptionCGI :: forall (m :: * -> *) a.
    MonadCatch m =>
    m a -> (SomeException -> m a) -> m a
    handleExceptionCGI = m a -> (SomeException -> m a) -> m a
    forall e a. (HasCallStack, Exception e) => m a -> (e -> m a) -> m a
    forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    m a -> (e -> m a) -> m a
    catch