| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Network.HTTP.Kinder.Header.Serialization
Contents
Description
HeaderNames define semantics for Text values seen in HTTP headers
over the wire. This module provides classes to map both to and from
these reprsentations.
- class HeaderEncode n a where
- headerEncode :: sing n -> a -> Maybe Text
- class HeaderDecode n a where
- headerDecode :: sing n -> Maybe Text -> Either String a
- type family AllHeaderEncodes hs :: Constraint
- type family AllHeaderDecodes hs :: Constraint
- headerEncodePair :: forall a n. HeaderEncode n a => Sing n -> a -> Maybe (CI ByteString, ByteString)
- headerEncodeBS :: HeaderEncode n a => sing n -> a -> Maybe ByteString
- headerDecodeBS :: HeaderDecode n a => sing n -> Maybe ByteString -> Either String a
- displaySetOpt :: Set Text -> Maybe Text
- uniqueSet :: (Ord v, HeaderEncode n (Set v)) => sing n -> [v] -> Maybe Text
- required :: (Text -> Either String a) -> Maybe Text -> Either String a
- withDefault :: a -> (Text -> Either String a) -> Maybe Text -> Either String a
Classes for encoding and decoding
class HeaderEncode n a where Source
Determines a Text representation for some value to be encoded as
a value of a given HeaderName. Any proxy can be passed as the first
argument, although Sing is a nice one to choose. Encodings may choose
to not be represented on the wire at all as desired by returning
Nothing. This implies default behavior.
Methods
headerEncode :: sing n -> a -> Maybe Text Source
Instances
| HeaderEncode ContentType MediaType Source | |
| HeaderEncode AccessControlAllowOrigin Text Source | |
| HeaderEncode AccessControlMaxAge NominalDiffTime Source | |
| HeaderEncode AccessControlAllowCredentials Bool Source | |
| HeaderEncode h t => HeaderEncode h (Maybe t) Source | Any value can be forced as optional if desired |
| HeaderEncode n (Raw Text) Source | Reports a "raw" value without interpretation |
| HeaderEncode AccessControlExposeHeaders [SomeHeaderName] Source | |
| HeaderEncode AccessControlExposeHeaders (Set SomeHeaderName) Source | |
| HeaderEncode AccessControlAllowMethods [Verb] Source | |
| HeaderEncode AccessControlAllowMethods (Set Verb) Source | |
| HeaderEncode AccessControlAllowHeaders [SomeHeaderName] Source | |
| HeaderEncode AccessControlAllowHeaders (Set SomeHeaderName) Source | |
| HeaderEncode Allow [Verb] Source | |
| HeaderEncode Allow (Set Verb) Source |
class HeaderDecode n a where Source
Interprets a (possibly missing) Text representation for some value
taking semantics at a given HeaderName. Any proxy can be passed as the
first argument, although Sing is a nice one to choose. If a value is
expected and no representation is provided then Nothing can be passed
seeking a default value (should one exist).
Instances
| HeaderDecode ContentType MediaType Source | |
| HeaderDecode h t => HeaderDecode h (Maybe t) Source | Any value may be only optionally captured as desired |
| HeaderDecode n (Raw Text) Source | Returns the raw header value |
| HeaderDecode Accept [Quality MediaType] Source |
Listing constraints to type-level lists
type family AllHeaderEncodes hs :: Constraint Source
For a given concrete type a, a list of pairs ts satisfies
if each AllHeaderEncode a ts(n, a) in ts has .HeaderEncode
n a
Equations
| AllHeaderEncodes `[]` = () | |
| AllHeaderEncodes (`(n, a)` : hs) = (HeaderEncode n a, AllHeaderEncodes hs) |
type family AllHeaderDecodes hs :: Constraint Source
For a given concrete type a, a list of pairs ts satisfies
if each AllHeaderDecode a ts(n, a) in ts has .HeaderDecode
n a
Equations
| AllHeaderDecodes `[]` = () | |
| AllHeaderDecodes (`(n, a)` : hs) = (HeaderDecode n a, AllHeaderDecodes hs) |
Extra serialization utilities
headerEncodePair :: forall a n. HeaderEncode n a => Sing n -> a -> Maybe (CI ByteString, ByteString) Source
Encode a HeaderName singleton and a HeaderEncode-represented value
as a pair of name and representation, ready to be sent over the wire.
headerEncodeBS :: HeaderEncode n a => sing n -> a -> Maybe ByteString Source
While the semantics of HTTP headers are built off of Text-like
values, usually we require a ByteString for emission. This helper
function converts a header value directly to a ByteString.
headerDecodeBS :: HeaderDecode n a => sing n -> Maybe ByteString -> Either String a Source
While HTTP header semantics are built off of Text-like values, we
usually read a raw ByteString from the wire. This helper function
combines a HeaderDecode with a UTF-8 decode so as to attempt to
deserialize header values directly from a ByteString.
Utilities for writing serialization instances
displaySetOpt :: Set Text -> Maybe Text Source
Output a set of text items as a comma-delimited list OR return nothing if the set is empty
uniqueSet :: (Ord v, HeaderEncode n (Set v)) => sing n -> [v] -> Maybe Text Source
Extend a HeaderEncode instance on to Set v[v].