snap-accept-0.2.1: Accept header branching for the Snap web framework

Safe HaskellNone
LanguageHaskell2010

Snap.Accept

Contents

Description

HTTP media type functionality as a complement to Snap's method and methods functions. Branches based on the value of the Accept or Accept-Language header of the current request, automatically setting the Content-Type or Content-Language header of the response as appropriate.

Synopsis

Branching

accept :: (FromHeader a, MonadSnap m) => a -> m b -> m b Source #

Runs a Snap monad only if the request's Accept* header allows for the given value. If accepted, the response's Content-* header is automatically filled in.

acceptMedia :: MonadSnap m => MediaType -> m a -> m a Source #

The accept function but specialised to MediaType.

acceptLanguage :: MonadSnap m => Language -> m a -> m a Source #

The accept function but specialised to Language.

accepts :: (FromHeader a, MonadSnap m) => [(a, m b)] -> m b Source #

Matches the Accept* header of the request to each of the values in the pairs of the given list, running the corresponding Snap monad in the pair that is most desired by the client. If two or more results arise with the same quality level and specificity, then the pair that appears earliest in the list is matched. On any match, the response's Content-* header is automatically filled in.

acceptsMedia :: MonadSnap m => [(MediaType, m a)] -> m a Source #

The accepts function but specialised to MediaType.

acceptsLanguage :: MonadSnap m => [(Language, m a)] -> m a Source #

The accepts function but specialised to Language.

Accept types

Header names

class (Accept a, RenderHeader a) => FromHeader a where Source #

The class of values that represent some Accept* header in a request and corresponding Content-* header in a response, such that the name of the header can be retrieved from the type.

Minimal complete definition

requestName, responseName, defaultValue

Methods

requestName :: Proxy a -> CI ByteString Source #

The name of the corresponding Accept* header for this type.

responseName :: Proxy a -> CI ByteString Source #

The name of the corresponding Content-* header for this type.

defaultValue :: Proxy a -> ByteString Source #

The default header value to use if the header is absent.