happstack-server-7.9.3: Web related tools and services.

Safe Haskell | None
Language | Haskell2010

Happstack.Server.Internal.Monads

Description

This module defines the Monad stack used by Happstack. You mostly don't want to be looking in here. Look in Happstack.Server.Monads instead.

Synopsis

- type Web a = WebT IO a
- type ServerPart a = ServerPartT IO a
- newtype ServerPartT (m :: Type -> Type) a = ServerPartT {
  - unServerPartT :: ReaderT Request (WebT m) a
  }
- runServerPartT :: forall (m :: Type -> Type) a. ServerPartT m a -> Request -> WebT m a
- withRequest :: forall (m :: Type -> Type) a. (Request -> WebT m a) -> ServerPartT m a
- anyRequest :: forall (m :: Type -> Type) a. Monad m => WebT m a -> ServerPartT m a
- mapServerPartT :: (UnWebT m a -> UnWebT n b) -> ServerPartT m a -> ServerPartT n b
- mapServerPartT' :: (Request -> UnWebT m a -> UnWebT n b) -> ServerPartT m a -> ServerPartT n b
- class Monad m => ServerMonad (m :: Type -> Type) where
  - askRq :: m Request
  - localRq :: (Request -> Request) -> m a -> m a
- smAskRqEnv :: (ServerMonad m, MonadIO m) => m ([(String, Input)], Maybe [(String, Input)], [(String, Cookie)])
- smLocalRqEnv :: (ServerMonad m, MonadIO m) => (([(String, Input)], Maybe [(String, Input)], [(String, Cookie)]) -> ([(String, Input)], Maybe [(String, Input)], [(String, Cookie)])) -> m b -> m b
- data SetAppend a
  - = Set a
  - | Append a
- extract :: SetAppend t -> t
- type FilterFun a = SetAppend (Dual (Endo a))
- unFilterFun :: FilterFun a -> a -> a
- filterFun :: (a -> a) -> FilterFun a
- newtype FilterT a (m :: Type -> Type) b = FilterT {
  - unFilterT :: WriterT (FilterFun a) m b
  }
- class Monad m => FilterMonad a (m :: Type -> Type) | m -> a where
  - setFilter :: (a -> a) -> m ()
  - composeFilter :: (a -> a) -> m ()
  - getFilter :: m b -> m (b, a -> a)
- ignoreFilters :: FilterMonad a m => m ()
- newtype WebT (m :: Type -> Type) a = WebT {
  - unWebT :: ExceptT Response (FilterT Response (MaybeT m)) a
  }
- type UnWebT (m :: Type -> Type) a = m (Maybe (Either Response a, FilterFun Response))
- class Monad m => WebMonad a (m :: Type -> Type) | m -> a where
  - finishWith :: a -> m b
- escape :: (WebMonad a m, FilterMonad a m) => m a -> m b
- escape' :: (WebMonad a m, FilterMonad a m) => a -> m b
- ununWebT :: WebT m a -> UnWebT m a
- mkWebT :: UnWebT m a -> WebT m a
- mapWebT :: (UnWebT m a -> UnWebT n b) -> WebT m a -> WebT n b
- localContext :: forall (m :: Type -> Type) a (m' :: Type -> Type). Monad m => (WebT m a -> WebT m' a) -> ServerPartT m a -> ServerPartT m' a
- multi :: forall (m :: Type -> Type) a. (Monad m, MonadPlus m) => [ServerPartT m a] -> ServerPartT m a
- debugFilter :: forall (m :: Type -> Type) a. (MonadIO m, Show a) => ServerPartT m a -> ServerPartT m a
- outputTraceMessage :: String -> a -> a
- mkFailMessage :: (FilterMonad Response m, WebMonad Response m) => String -> m b
- failResponse :: String -> Response
- failHtml :: String -> String
- escapeString :: String -> String
- escapeHTTP :: (ServerMonad m, MonadIO m) => (TimeoutIO -> IO ()) -> m a

# Documentation

type Web a = WebT IO a Source #

An alias for `WebT` when using `IO`.

type ServerPart a = ServerPartT IO a Source #

An alias for ``ServerPartT` `IO``

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

`ServerPartT` is a rich, featureful monad for web development.

see also: `simpleHTTP`, `ServerMonad`, `FilterMonad`, `WebMonad`, and `HasRqData`

Constructors

ServerPartT |

Fields

- unServerPartT :: ReaderT Request (WebT m) a

#### Instances

Instances details

MonadTransControl ServerPartT Source # |

Instance details

Defined in Happstack.Server.Internal.Monads

Associated Types

type StT ServerPartT a |
Instance details Defined in Happstack.Server.Internal.Monads type StT ServerPartT a = StT WebT (StT (ReaderT Request) a)

Methods

liftWith :: Monad m => (Run ServerPartT -> m a) -> ServerPartT m a Source #

restoreT :: Monad m => m (StT ServerPartT a) -> ServerPartT m a Source #

MonadTrans ServerPartT Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods lift :: Monad m => m a -> ServerPartT m a Source #
Monad m => FilterMonad Response (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (Response -> Response) -> ServerPartT m () Source # composeFilter :: (Response -> Response) -> ServerPartT m () Source # getFilter :: ServerPartT m b -> ServerPartT m (b, Response -> Response) Source #
Monad m => WebMonad Response (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: Response -> ServerPartT m b Source #
MonadBaseControl b m => MonadBaseControl b (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftBaseWith :: (RunInBase (ServerPartT m) b -> b a) -> ServerPartT m a Source # restoreM :: StM (ServerPartT m) a -> ServerPartT m a Source #
(Monad m, MonadError e m) => MonadError e (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods throwError :: e -> ServerPartT m a Source # catchError :: ServerPartT m a -> (e -> ServerPartT m a) -> ServerPartT m a Source #
(Monad m, MonadReader r m) => MonadReader r (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods ask :: ServerPartT m r Source # local :: (r -> r) -> ServerPartT m a -> ServerPartT m a Source # reader :: (r -> a) -> ServerPartT m a Source #
(Monad m, MonadState s m) => MonadState s (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods get :: ServerPartT m s Source # put :: s -> ServerPartT m () Source # state :: (s -> (a, s)) -> ServerPartT m a Source #
(Monad m, MonadWriter w m) => MonadWriter w (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods writer :: (a, w) -> ServerPartT m a Source # tell :: w -> ServerPartT m () Source # listen :: ServerPartT m a -> ServerPartT m (a, w) Source # pass :: ServerPartT m (a, w -> w) -> ServerPartT m a Source #
MonadBase b m => MonadBase b (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftBase :: b α -> ServerPartT m α Source #
MonadIO m => MonadIO (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftIO :: IO a -> ServerPartT m a Source #
MonadCatch m => MonadCatch (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods catch :: (HasCallStack, Exception e) => ServerPartT m a -> (e -> ServerPartT m a) -> ServerPartT m a Source #
MonadThrow m => MonadThrow (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods throwM :: (HasCallStack, Exception e) => e -> ServerPartT m a Source #
(Functor m, MonadPlus m) => Alternative (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods empty :: ServerPartT m a Source # (<|>) :: ServerPartT m a -> ServerPartT m a -> ServerPartT m a Source # some :: ServerPartT m a -> ServerPartT m [a] Source # many :: ServerPartT m a -> ServerPartT m [a] Source #
(Monad m, Functor m) => Applicative (ServerPartT m) Source # |

Instance details

Defined in Happstack.Server.Internal.Monads

Methods

pure :: a -> ServerPartT m a Source #

(<*>) :: ServerPartT m (a -> b) -> ServerPartT m a -> ServerPartT m b Source #

liftA2 :: (a -> b -> c) -> ServerPartT m a -> ServerPartT m b -> ServerPartT m c Source #

(*>) :: ServerPartT m a -> ServerPartT m b -> ServerPartT m b Source #

(<*) :: ServerPartT m a -> ServerPartT m b -> ServerPartT m a Source #

Functor m => Functor (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods fmap :: (a -> b) -> ServerPartT m a -> ServerPartT m b Source # (<$) :: a -> ServerPartT m b -> ServerPartT m a Source #
Monad m => Monad (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods (>>=) :: ServerPartT m a -> (a -> ServerPartT m b) -> ServerPartT m b Source # (>>) :: ServerPartT m a -> ServerPartT m b -> ServerPartT m b Source # return :: a -> ServerPartT m a Source #
MonadPlus m => MonadPlus (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods mzero :: ServerPartT m a Source # mplus :: ServerPartT m a -> ServerPartT m a -> ServerPartT m a Source #
MonadFail m => MonadFail (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods fail :: String -> ServerPartT m a Source #
Monad m => ServerMonad (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: ServerPartT m Request Source # localRq :: (Request -> Request) -> ServerPartT m a -> ServerPartT m a Source #
(Functor m, Monad m, MonadPlus m, MonadIO m) => Happstack (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Monads
(MonadIO m, MonadPlus m) => HasRqData (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.RqData Methods askRqEnv :: ServerPartT m RqEnv Source # localRqEnv :: (RqEnv -> RqEnv) -> ServerPartT m a -> ServerPartT m a Source # rqDataError :: Errors String -> ServerPartT m a Source #
(Monad m, MonadPlus m) => Monoid (ServerPartT m a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods mempty :: ServerPartT m a Source # mappend :: ServerPartT m a -> ServerPartT m a -> ServerPartT m a Source # mconcat :: [ServerPartT m a] -> ServerPartT m a Source #
(Monad m, MonadPlus m) => Semigroup (ServerPartT m a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods (<>) :: ServerPartT m a -> ServerPartT m a -> ServerPartT m a Source # sconcat :: NonEmpty (ServerPartT m a) -> ServerPartT m a Source # stimes :: Integral b => b -> ServerPartT m a -> ServerPartT m a Source #
type StT ServerPartT a Source # |
Instance details Defined in Happstack.Server.Internal.Monads type StT ServerPartT a = StT WebT (StT (ReaderT Request) a)
type StM (ServerPartT m) a Source # |
Instance details Defined in Happstack.Server.Internal.Monads type StM (ServerPartT m) a = ComposeSt ServerPartT m a

runServerPartT :: forall (m :: Type -> Type) a. ServerPartT m a -> Request -> WebT m a Source #

Particularly useful when combined with `runWebT` to produce a `m (`Maybe` `Response`)` from a `Request`.

withRequest :: forall (m :: Type -> Type) a. (Request -> WebT m a) -> ServerPartT m a Source #

function for lifting WebT to ServerPartT

NOTE: This is mostly for internal use. If you want to access the `Request` in user-code see `askRq` from `ServerMonad`.

    do request <- askRq
       ...

anyRequest :: forall (m :: Type -> Type) a. Monad m => WebT m a -> ServerPartT m a Source #

A constructor for a `ServerPartT` when you don't care about the request.

NOTE: This is mostly for internal use. If you think you need to use it in your own code, you might consider asking on the mailing list or IRC to find out if there is an alternative solution.

mapServerPartT :: (UnWebT m a -> UnWebT n b) -> ServerPartT m a -> ServerPartT n b Source #

Apply a function to transform the inner monad of ``ServerPartT` m`.

Often used when transforming a monad with `ServerPartT`, since `simpleHTTP` requires a ``ServerPartT` `IO` a`. Refer to `UnWebT` for an explanation of the structure of the monad.

Here is an example. Suppose you want to embed an `ErrorT` into your `ServerPartT` to enable `throwError` and `catchError` in your `Monad`.

    type MyServerPartT e m a = ServerPartT (ErrorT e m) a

Now suppose you want to pass `MyServerPartT` into a function that demands a ``ServerPartT` `IO` a` (e.g. `simpleHTTP`). You can provide the function:

      unpackErrorT :: (Monad m, Show e) => UnWebT (ErrorT e m) a -> UnWebT m a
      unpackErrorT et = do
         eitherV <- runErrorT et
         return $ case eitherV of
             Left err -> Just (Left $ toResponse $
                                      "Catastrophic failure " ++ show err
                              , filterFun $ \r -> r{rsCode = 500})
             Right x -> x

With `unpackErrorT` you can now call `simpleHTTP`. Just wrap your `ServerPartT` list.

     simpleHTTP nullConf $ mapServerPartT unpackErrorT (myPart `catchError` myHandler)

Or alternatively:

     simpleHTTP' unpackErrorT nullConf (myPart `catchError` myHandler)

Also see `spUnwrapErrorT` for a more sophisticated version of this function.

mapServerPartT' :: (Request -> UnWebT m a -> UnWebT n b) -> ServerPartT m a -> ServerPartT n b Source #

A variant of `mapServerPartT` where the first argument also takes a `Request`. Useful if you want to `runServerPartT` on a different `ServerPartT` inside your monad (see `spUnwrapErrorT`).

class Monad m => ServerMonad (m :: Type -> Type) where Source #

The `ServerMonad` class provides methods for reading or locally modifying the `Request`. It is essentially a specialized version of the `MonadReader` class. Providing the unique names, `askRq` and `localRq` makes it easier to use `ServerPartT` and `ReaderT` together.

Methods

askRq :: m Request Source #

localRq :: (Request -> Request) -> m a -> m a Source #

#### Instances

Instances details

Monad m => ServerMonad (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: ServerPartT m Request Source # localRq :: (Request -> Request) -> ServerPartT m a -> ServerPartT m a Source #
ServerMonad m => ServerMonad (ExceptT e m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: ExceptT e m Request Source # localRq :: (Request -> Request) -> ExceptT e m a -> ExceptT e m a Source #
ServerMonad m => ServerMonad (ReaderT r m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: ReaderT r m Request Source # localRq :: (Request -> Request) -> ReaderT r m a -> ReaderT r m a Source #
ServerMonad m => ServerMonad (StateT s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: StateT s m Request Source # localRq :: (Request -> Request) -> StateT s m a -> StateT s m a Source #
ServerMonad m => ServerMonad (StateT s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: StateT s m Request Source # localRq :: (Request -> Request) -> StateT s m a -> StateT s m a Source #
(ServerMonad m, Monoid w) => ServerMonad (WriterT w m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: WriterT w m Request Source # localRq :: (Request -> Request) -> WriterT w m a -> WriterT w m a Source #
(ServerMonad m, Monoid w) => ServerMonad (WriterT w m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: WriterT w m Request Source # localRq :: (Request -> Request) -> WriterT w m a -> WriterT w m a Source #
(ServerMonad m, Monoid w) => ServerMonad (RWST r w s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: RWST r w s m Request Source # localRq :: (Request -> Request) -> RWST r w s m a -> RWST r w s m a Source #
(ServerMonad m, Monoid w) => ServerMonad (RWST r w s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods askRq :: RWST r w s m Request Source # localRq :: (Request -> Request) -> RWST r w s m a -> RWST r w s m a Source #

smAskRqEnv :: (ServerMonad m, MonadIO m) => m ([(String, Input)], Maybe [(String, Input)], [(String, Cookie)]) Source #

Implementation of `askRqEnv` for arbitrary `ServerMonad`.

smLocalRqEnv :: (ServerMonad m, MonadIO m) => (([(String, Input)], Maybe [(String, Input)], [(String, Cookie)]) -> ([(String, Input)], Maybe [(String, Input)], [(String, Cookie)])) -> m b -> m b Source #

Implementation of `localRqEnv` for arbitrary `ServerMonad`.

data SetAppend a Source #

A monoid operation container. If `a` is a monoid, then `SetAppend` is a monoid with the following behaviors:

     Set    x `mappend` Append y = Set    (x `mappend` y)
     Append x `mappend` Append y = Append (x `mappend` y)
     _        `mappend` Set y    = Set y

A simple way of summarizing this is, if the right side is `Append`, then the right is appended to the left. If the right side is `Set`, then the left side is ignored.

Constructors

Set a |
Append a |

#### Instances

Instances details

Functor SetAppend Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods fmap :: (a -> b) -> SetAppend a -> SetAppend b Source # (<$) :: a -> SetAppend b -> SetAppend a Source #
Monoid a => Monoid (SetAppend a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods mempty :: SetAppend a Source # mappend :: SetAppend a -> SetAppend a -> SetAppend a Source # mconcat :: [SetAppend a] -> SetAppend a Source #
Monoid a => Semigroup (SetAppend a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods (<>) :: SetAppend a -> SetAppend a -> SetAppend a Source # sconcat :: NonEmpty (SetAppend a) -> SetAppend a Source # stimes :: Integral b => b -> SetAppend a -> SetAppend a Source #
Show a => Show (SetAppend a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods showsPrec :: Int -> SetAppend a -> ShowS Source # show :: SetAppend a -> String Source # showList :: [SetAppend a] -> ShowS Source #
Eq a => Eq (SetAppend a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods (==) :: SetAppend a -> SetAppend a -> Bool Source # (/=) :: SetAppend a -> SetAppend a -> Bool Source #

extract :: SetAppend t -> t Source #

Extract the value from a `SetAppend`. Note that a `SetAppend` is actually a `CoPointed` from: http://hackage.haskell.org/packages/archive/category-extras/latest/doc/html/Control-Functor-Pointed.html But lets not drag in that dependency. yet...

type FilterFun a = SetAppend (Dual (Endo a)) Source #

`FilterFun` is a lot more fun to type than ``SetAppend` (`Dual` (`Endo` a))`.

unFilterFun :: FilterFun a -> a -> a Source #

filterFun :: (a -> a) -> FilterFun a Source #

turn a function into a `FilterFun`. Primarily used with `mapServerPartT`

newtype FilterT a (m :: Type -> Type) b Source #

Constructors

FilterT |

Fields

- unFilterT :: WriterT (FilterFun a) m b

#### Instances

Instances details

Monad m => FilterMonad a (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (a -> a) -> FilterT a m () Source # composeFilter :: (a -> a) -> FilterT a m () Source # getFilter :: FilterT a m b -> FilterT a m (b, a -> a) Source #
MonadBaseControl b m => MonadBaseControl b (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftBaseWith :: (RunInBase (FilterT a m) b -> b a0) -> FilterT a m a0 Source # restoreM :: StM (FilterT a m) a0 -> FilterT a m a0 Source #
MonadBase b m => MonadBase b (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftBase :: b α -> FilterT a m α Source #
MonadTransControl (FilterT a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftWith :: Monad m => (Run (FilterT a) -> m a0) -> FilterT a m a0 Source # restoreT :: Monad m => m (StT (FilterT a) a0) -> FilterT a m a0 Source #
MonadTrans (FilterT a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods lift :: Monad m => m a0 -> FilterT a m a0 Source #
MonadIO m => MonadIO (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftIO :: IO a0 -> FilterT a m a0 Source #
MonadCatch m => MonadCatch (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods catch :: (HasCallStack, Exception e) => FilterT a m a0 -> (e -> FilterT a m a0) -> FilterT a m a0 Source #
MonadThrow m => MonadThrow (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods throwM :: (HasCallStack, Exception e) => e -> FilterT a m a0 Source #
Applicative m => Applicative (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods pure :: a0 -> FilterT a m a0 Source # (<*>) :: FilterT a m (a0 -> b) -> FilterT a m a0 -> FilterT a m b Source # liftA2 :: (a0 -> b -> c) -> FilterT a m a0 -> FilterT a m b -> FilterT a m c Source # (*>) :: FilterT a m a0 -> FilterT a m b -> FilterT a m b Source # (<*) :: FilterT a m a0 -> FilterT a m b -> FilterT a m a0 Source #
Functor m => Functor (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods fmap :: (a0 -> b) -> FilterT a m a0 -> FilterT a m b Source # (<$) :: a0 -> FilterT a m b -> FilterT a m a0 Source #
Monad m => Monad (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods (>>=) :: FilterT a m a0 -> (a0 -> FilterT a m b) -> FilterT a m b Source # (>>) :: FilterT a m a0 -> FilterT a m b -> FilterT a m b Source # return :: a0 -> FilterT a m a0 Source #
type StT (FilterT a) b Source # |
Instance details Defined in Happstack.Server.Internal.Monads type StT (FilterT a) b = StT (WriterT (FilterFun a)) b
type StM (FilterT a m) c Source # |
Instance details Defined in Happstack.Server.Internal.Monads type StM (FilterT a m) c = ComposeSt (FilterT a) m c

class Monad m => FilterMonad a (m :: Type -> Type) | m -> a where Source #

A set of functions for manipulating filters.

`ServerPartT` implements `FilterMonad` `Response` so these methods are the fundamental ways of manipulating `Response` values.

Methods

setFilter :: (a -> a) -> m () Source #

Ignores all previous alterations to your filter

As an example:

    do
      composeFilter f
      setFilter g
      return "Hello World"

The ``setFilter` g` will cause the first ``composeFilter` f` to be ignored.

composeFilter :: (a -> a) -> m () Source #

Composes your filter function with the existing filter function.

getFilter :: m b -> m (b, a -> a) Source #

Retrieves the filter from the environment.

#### Instances

Instances details

Monad m => FilterMonad Response (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (Response -> Response) -> ServerPartT m () Source # composeFilter :: (Response -> Response) -> ServerPartT m () Source # getFilter :: ServerPartT m b -> ServerPartT m (b, Response -> Response) Source #
Monad m => FilterMonad Response (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (Response -> Response) -> WebT m () Source # composeFilter :: (Response -> Response) -> WebT m () Source # getFilter :: WebT m b -> WebT m (b, Response -> Response) Source #
Monad m => FilterMonad a (FilterT a m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (a -> a) -> FilterT a m () Source # composeFilter :: (a -> a) -> FilterT a m () Source # getFilter :: FilterT a m b -> FilterT a m (b, a -> a) Source #
FilterMonad a m => FilterMonad a (ExceptT e m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (a -> a) -> ExceptT e m () Source # composeFilter :: (a -> a) -> ExceptT e m () Source # getFilter :: ExceptT e m b -> ExceptT e m (b, a -> a) Source #
FilterMonad res m => FilterMonad res (ReaderT r m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (res -> res) -> ReaderT r m () Source # composeFilter :: (res -> res) -> ReaderT r m () Source # getFilter :: ReaderT r m b -> ReaderT r m (b, res -> res) Source #
FilterMonad res m => FilterMonad res (StateT s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (res -> res) -> StateT s m () Source # composeFilter :: (res -> res) -> StateT s m () Source # getFilter :: StateT s m b -> StateT s m (b, res -> res) Source #
FilterMonad res m => FilterMonad res (StateT s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (res -> res) -> StateT s m () Source # composeFilter :: (res -> res) -> StateT s m () Source # getFilter :: StateT s m b -> StateT s m (b, res -> res) Source #
(FilterMonad res m, Monoid w) => FilterMonad res (WriterT w m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (res -> res) -> WriterT w m () Source # composeFilter :: (res -> res) -> WriterT w m () Source # getFilter :: WriterT w m b -> WriterT w m (b, res -> res) Source #
(FilterMonad res m, Monoid w) => FilterMonad res (WriterT w m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (res -> res) -> WriterT w m () Source # composeFilter :: (res -> res) -> WriterT w m () Source # getFilter :: WriterT w m b -> WriterT w m (b, res -> res) Source #
(FilterMonad res m, Monoid w) => FilterMonad res (RWST r w s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (res -> res) -> RWST r w s m () Source # composeFilter :: (res -> res) -> RWST r w s m () Source # getFilter :: RWST r w s m b -> RWST r w s m (b, res -> res) Source #
(FilterMonad res m, Monoid w) => FilterMonad res (RWST r w s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (res -> res) -> RWST r w s m () Source # composeFilter :: (res -> res) -> RWST r w s m () Source # getFilter :: RWST r w s m b -> RWST r w s m (b, res -> res) Source #

ignoreFilters :: FilterMonad a m => m () Source #

Resets all your filters. An alias for ``setFilter` `id``.

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

The basic `Response` building object.

Constructors

WebT |

Fields

- unWebT :: ExceptT Response (FilterT Response (MaybeT m)) a

#### Instances

Instances details

MonadTransControl WebT Source # |

Instance details

Defined in Happstack.Server.Internal.Monads

Associated Types

type StT WebT a |
Instance details Defined in Happstack.Server.Internal.Monads type StT WebT a = StT MaybeT (StT (FilterT Response) (StT (ExceptT Response) a))

Methods

liftWith :: Monad m => (Run WebT -> m a) -> WebT m a Source #

restoreT :: Monad m => m (StT WebT a) -> WebT m a Source #

MonadTrans WebT Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods lift :: Monad m => m a -> WebT m a Source #
Monad m => FilterMonad Response (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods setFilter :: (Response -> Response) -> WebT m () Source # composeFilter :: (Response -> Response) -> WebT m () Source # getFilter :: WebT m b -> WebT m (b, Response -> Response) Source #
Monad m => WebMonad Response (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: Response -> WebT m b Source #
MonadBaseControl b m => MonadBaseControl b (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftBaseWith :: (RunInBase (WebT m) b -> b a) -> WebT m a Source # restoreM :: StM (WebT m) a -> WebT m a Source #
MonadError e m => MonadError e (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods throwError :: e -> WebT m a Source # catchError :: WebT m a -> (e -> WebT m a) -> WebT m a Source #
MonadReader r m => MonadReader r (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods ask :: WebT m r Source # local :: (r -> r) -> WebT m a -> WebT m a Source # reader :: (r -> a) -> WebT m a Source #
MonadState st m => MonadState st (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods get :: WebT m st Source # put :: st -> WebT m () Source # state :: (st -> (a, st)) -> WebT m a Source #
MonadWriter w m => MonadWriter w (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods writer :: (a, w) -> WebT m a Source # tell :: w -> WebT m () Source # listen :: WebT m a -> WebT m (a, w) Source # pass :: WebT m (a, w -> w) -> WebT m a Source #
MonadBase b m => MonadBase b (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftBase :: b α -> WebT m α Source #
MonadIO m => MonadIO (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods liftIO :: IO a -> WebT m a Source #
MonadCatch m => MonadCatch (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods catch :: (HasCallStack, Exception e) => WebT m a -> (e -> WebT m a) -> WebT m a Source #
MonadThrow m => MonadThrow (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods throwM :: (HasCallStack, Exception e) => e -> WebT m a Source #
(Functor m, MonadPlus m) => Alternative (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods empty :: WebT m a Source # (<|>) :: WebT m a -> WebT m a -> WebT m a Source # some :: WebT m a -> WebT m [a] Source # many :: WebT m a -> WebT m [a] Source #
(Monad m, Functor m) => Applicative (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods pure :: a -> WebT m a Source # (<*>) :: WebT m (a -> b) -> WebT m a -> WebT m b Source # liftA2 :: (a -> b -> c) -> WebT m a -> WebT m b -> WebT m c Source # (*>) :: WebT m a -> WebT m b -> WebT m b Source # (<*) :: WebT m a -> WebT m b -> WebT m a Source #
Functor m => Functor (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods fmap :: (a -> b) -> WebT m a -> WebT m b Source # (<$) :: a -> WebT m b -> WebT m a Source #
Monad m => Monad (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods (>>=) :: WebT m a -> (a -> WebT m b) -> WebT m b Source # (>>) :: WebT m a -> WebT m b -> WebT m b Source # return :: a -> WebT m a Source #
(Monad m, MonadPlus m) => MonadPlus (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods mzero :: WebT m a Source # mplus :: WebT m a -> WebT m a -> WebT m a Source #
MonadFail m => MonadFail (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods fail :: String -> WebT m a Source #
(Monad m, MonadPlus m) => Monoid (WebT m a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods mempty :: WebT m a Source # mappend :: WebT m a -> WebT m a -> WebT m a Source # mconcat :: [WebT m a] -> WebT m a Source #
(Monad m, MonadPlus m) => Semigroup (WebT m a) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods (<>) :: WebT m a -> WebT m a -> WebT m a Source # sconcat :: NonEmpty (WebT m a) -> WebT m a Source # stimes :: Integral b => b -> WebT m a -> WebT m a Source #
type StT WebT a Source # |
Instance details Defined in Happstack.Server.Internal.Monads type StT WebT a = StT MaybeT (StT (FilterT Response) (StT (ExceptT Response) a))
type StM (WebT m) a Source # |
Instance details Defined in Happstack.Server.Internal.Monads type StM (WebT m) a = ComposeSt WebT m a

type UnWebT (m :: Type -> Type) a = m (Maybe (Either Response a, FilterFun Response)) Source #

`UnWebT` is almost exclusively used with `mapServerPartT`. If you are not using `mapServerPartT` then you do not need to wrap your head around this type. If you are -- the type is not as complex as it first appears.

It is worth discussing the unpacked structure of `WebT` a bit as it's exposed in `mapServerPartT` and `mapWebT`.

A fully unpacked `WebT` has a structure that looks like:

    ununWebT $ WebT m a :: m (Maybe (Either Response a, FilterFun Response))

So, ignoring `m`, as it is just the containing `Monad`, the outermost layer is a `Maybe`. This is `Nothing` if `mzero` was called or ``Just` (`Either` `Response` a, `SetAppend` (`Endo` `Response`))` if `mzero` wasn't called. Inside the `Maybe`, there is a pair. The second element of the pair is our filter function ``FilterFun` `Response``. ``FilterFun` `Response`` is a type alias for ``SetAppend` (`Dual` (`Endo` `Response`))`. This is just a wrapper for a ``Response` -> `Response`` function with a particular `Monoid` behavior. The value

     Append (Dual (Endo f))

Causes `f` to be composed with the previous filter.

     Set (Dual (Endo f))

Causes `f` to not be composed with the previous filter.

Finally, the first element of the pair is either ``Left` `Response`` or ``Right` a`.

Another way of looking at all these pieces is from the behaviors they control. The `Maybe` controls the `mzero` behavior. ``Set` (`Endo` f)` comes from the `setFilter` behavior. Likewise, ``Append` (`Endo` f)` is from `composeFilter`. ``Left` `Response`` is what you get when you call `finishWith` and ``Right` a` is the normal exit.

An example case statement looks like:

     ex1 webt = do
       val <- ununWebT webt
       case val of
           Nothing -> Nothing  -- this is the interior value when mzero was used
           Just (Left r, f) -> Just (Left r, f) -- r is the value that was passed into "finishWith"
                                                -- f is our filter function
           Just (Right a, f) -> Just (Right a, f) -- a is our normal monadic value
                                                  -- f is still our filter function

class Monad m => WebMonad a (m :: Type -> Type) | m -> a where Source #

`WebMonad` provides a means to end the current computation and return a `Response` immediately. This provides an alternate escape route. In particular it has a monadic value of any type. And unless you call ``setFilter` `id`` first your response filters will be applied normally.

Extremely useful when you're deep inside a monad and decide that you want to return a completely different content type, since it doesn't force you to convert all your return types to `Response` early just to accommodate this.

see also: `escape` and `escape'`

Methods

finishWith Source #

Arguments

:: a | value to return (For `ServerPart`, `a` will always be the type `Response`)
-> m b |

#### Instances

Instances details

Monad m => WebMonad Response (ServerPartT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: Response -> ServerPartT m b Source #
Monad m => WebMonad Response (WebT m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: Response -> WebT m b Source #
WebMonad a m => WebMonad a (ExceptT e m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: a -> ExceptT e m b Source #
WebMonad a m => WebMonad a (ReaderT r m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: a -> ReaderT r m b Source #
WebMonad a m => WebMonad a (StateT s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: a -> StateT s m b Source #
WebMonad a m => WebMonad a (StateT s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: a -> StateT s m b Source #
(WebMonad a m, Monoid w) => WebMonad a (WriterT w m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: a -> WriterT w m b Source #
(WebMonad a m, Monoid w) => WebMonad a (WriterT w m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: a -> WriterT w m b Source #
(WebMonad a m, Monoid w) => WebMonad a (RWST r w s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: a -> RWST r w s m b Source #
(WebMonad a m, Monoid w) => WebMonad a (RWST r w s m) Source # |
Instance details Defined in Happstack.Server.Internal.Monads Methods finishWith :: a -> RWST r w s m b Source #

escape :: (WebMonad a m, FilterMonad a m) => m a -> m b Source #

Used to ignore all your filters and immediately end the computation. A combination of `ignoreFilters` and `finishWith`.

escape' :: (WebMonad a m, FilterMonad a m) => a -> m b Source #

An alternate form of `escape` that can be easily used within a do block.

ununWebT :: WebT m a -> UnWebT m a Source #

For when you really need to unpack a `WebT` entirely (and not just unwrap the first layer with `unWebT`).

mkWebT :: UnWebT m a -> WebT m a Source #

For wrapping a `WebT` back up. ``mkWebT` . `ununWebT` = `id``

mapWebT :: (UnWebT m a -> UnWebT n b) -> WebT m a -> WebT n b Source #

See `mapServerPartT` for a discussion of this function.

localContext :: forall (m :: Type -> Type) a (m' :: Type -> Type). Monad m => (WebT m a -> WebT m' a) -> ServerPartT m a -> ServerPartT m' a Source #

This is kinda like a very oddly shaped `mapServerPartT` or `mapWebT`. You probably want one or the other of those.

multi :: forall (m :: Type -> Type) a. (Monad m, MonadPlus m) => [ServerPartT m a] -> ServerPartT m a Source #

Deprecated: Use msum instead

Deprecated: use `msum`.

debugFilter :: forall (m :: Type -> Type) a. (MonadIO m, Show a) => ServerPartT m a -> ServerPartT m a Source #

Deprecated: This function appears to do nothing.

What is this for, exactly? I don't understand why `Show a` is even in the context Deprecated: This function appears to do nothing at all. If it use it, let us know why.

outputTraceMessage :: String -> a -> a Source #

mkFailMessage :: (FilterMonad Response m, WebMonad Response m) => String -> m b Source #

failResponse :: String -> Response Source #

failHtml :: String -> String Source #

escapeString :: String -> String Source #

escapeHTTP :: (ServerMonad m, MonadIO m) => (TimeoutIO -> IO ()) -> m a Source #