Safe Haskell | None |
---|---|
Language | Haskell2010 |
contains various matching utilities
- getBodyLazy :: MonadRespond m => m ByteString
- getBodyStrict :: MonadRespond m => m ByteString
- extractBodyLazy :: (ReportableError e, FromBody e a, MonadRespond m) => m (Either e a)
- extractBodyStrict :: (ReportableError e, FromBody e a, MonadRespond m) => m (Either e a)
- withRequiredBody :: (ReportableError e, FromBody e a, MonadRespond m) => (a -> m ResponseReceived) -> m ResponseReceived
- withRequiredBody' :: (ReportableError e, FromBody e a, MonadRespond m) => (a -> m ResponseReceived) -> m ResponseReceived
- authenticate :: (MonadRespond m, ReportableError e) => m (Either e a) -> (a -> m ResponseReceived) -> m ResponseReceived
- reauthenticate :: (MonadRespond m, ReportableError e) => Maybe a -> m (Either e a) -> (a -> m ResponseReceived) -> m ResponseReceived
- authorize :: (ReportableError e, MonadRespond m) => Maybe e -> m ResponseReceived -> m ResponseReceived
- authorizeBool :: (ReportableError e, MonadRespond m) => e -> Bool -> m ResponseReceived -> m ResponseReceived
- authorizeE :: (ReportableError e, MonadRespond m) => Either e a -> (a -> m ResponseReceived) -> m ResponseReceived
- routeAccept :: MonadRespond m => m a -> [(MediaType, m a)] -> m a
- checkAccepts :: MonadRespond m => [MediaType] -> m ResponseReceived -> m ResponseReceived
extracting the request body
getBodyLazy :: MonadRespond m => m ByteString Source
gets the body as a lazy ByteString using lazy IO (see lazyRequestBody
)
getBodyStrict :: MonadRespond m => m ByteString Source
gets the body as a lazy ByteString using strict IO (see strictRequestBody
)
extraction using FromBody
extractBodyLazy :: (ReportableError e, FromBody e a, MonadRespond m) => m (Either e a) Source
use a FromBody instance to parse the body. uses getBodyLazy
to
lazily load the body data.
extractBodyStrict :: (ReportableError e, FromBody e a, MonadRespond m) => m (Either e a) Source
uses a FromBody instance to parse the body. uses getBodyStrict
to
load the body strictly.
withRequiredBody :: (ReportableError e, FromBody e a, MonadRespond m) => (a -> m ResponseReceived) -> m ResponseReceived Source
extracts the body using extractBodyLazy
. runs the inner action only
if the body could be loaded and parseda using the FromBody instance;
otherwise responds with the reportable error by calling
handleBodyParseFailure
.
withRequiredBody' :: (ReportableError e, FromBody e a, MonadRespond m) => (a -> m ResponseReceived) -> m ResponseReceived Source
extracts the body using extractBodyStrict
. runs the inner action only
if the body could be loaded and parseda using the FromBody instance;
otherwise responds with the reportable error by calling
handleBodyParseFailure
.
authentication and authorization
authenticate :: (MonadRespond m, ReportableError e) => m (Either e a) -> (a -> m ResponseReceived) -> m ResponseReceived Source
authenticate uses the result of the authentication action (if it
succssfully produced a result) to run the inner action function.
otherwise, it uses handleAuthFailed
.
reauthenticate :: (MonadRespond m, ReportableError e) => Maybe a -> m (Either e a) -> (a -> m ResponseReceived) -> m ResponseReceived Source
reauthenticate tries to use a prior authentication value to run the
inner action; if it's not availalble, it falls back to authenticate
to
apply the auth action and run the inner action.
authorize :: (ReportableError e, MonadRespond m) => Maybe e -> m ResponseReceived -> m ResponseReceived Source
if given an error report value , respond immediately using
handleDenied
. otherwise, run the inner route.
authorizeBool :: (ReportableError e, MonadRespond m) => e -> Bool -> m ResponseReceived -> m ResponseReceived Source
if the bool is true, run the inner. otherwise, handleDenied the report.
authorizeE :: (ReportableError e, MonadRespond m) => Either e a -> (a -> m ResponseReceived) -> m ResponseReceived Source
authorize using an Either; if it's Left, fail using handleDenied
on
the contained ReportableError. if it's right, run the inner action using
the contained value,
content negotiation
:: MonadRespond m | |
=> m a | default action - do this if nothing matches |
-> [(MediaType, m a)] | actions to perform for each accepted media type |
-> m a | chosen action |
selects action by accept header
checkAccepts :: MonadRespond m => [MediaType] -> m ResponseReceived -> m ResponseReceived Source
defends the inner routes by first checking the Accept header and failing if it cannot accept any media type in the list