@@ -31,9 +31,8 @@ module Servant.API.ResponseHeaders
33import Data.ByteString.Char8 as BS (pack, unlines, init)
33import Data.ByteString.Char8 as BS (pack, unlines, init)
34−import Data.ByteString.Conversion (--ToByteString, toByteString',
35− FromByteString, fromByteString)
36−import Web.HttpApiData (ToHttpApiData,toHeader)
34+import Web.HttpApiData (ToHttpApiData,toHeader
35+ ,FromHttpApiData,parseHeader)
37import qualified Data.CaseInsensitive as CI
36import qualified Data.CaseInsensitive as CI
38import Data.Proxy
37import Data.Proxy
39import GHC.TypeLits (KnownSymbol, symbolVal)
38import GHC.TypeLits (KnownSymbol, symbolVal)
@@ -69,17 +68,17 @@ class BuildHeadersTo hs where
69instance OVERLAPPING_ BuildHeadersTo '[] where
68instance OVERLAPPING_ BuildHeadersTo '[] where
70 buildHeadersTo _ = HNil
69 buildHeadersTo _ = HNil
72−instance OVERLAPPABLE_ ( FromByteString v, BuildHeadersTo xs, KnownSymbol h )
71+instance OVERLAPPABLE_ ( FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h )
73 => BuildHeadersTo ((Header h v) ': xs) where
72 => BuildHeadersTo ((Header h v) ': xs) where
74 buildHeadersTo headers =
73 buildHeadersTo headers =
75 let wantedHeader = CI.mk . pack $ symbolVal (Proxy :: Proxy h)
74 let wantedHeader = CI.mk . pack $ symbolVal (Proxy :: Proxy h)
76 matching = snd <$> filter (\(h, _) -> h == wantedHeader) headers
75 matching = snd <$> filter (\(h, _) -> h == wantedHeader) headers
77 in case matching of
76 in case matching of
78 [] -> MissingHeader `HCons` buildHeadersTo headers
77 [] -> MissingHeader `HCons` buildHeadersTo headers
79− xs -> case fromByteString (BS.init $ BS.unlines xs) of
78+ xs -> case parseHeader (BS.init $ BS.unlines xs) of
80− Nothing -> UndecodableHeader (BS.init $ BS.unlines xs)
79+ Left _err -> UndecodableHeader (BS.init $ BS.unlines xs)
81 `HCons` buildHeadersTo headers
80 `HCons` buildHeadersTo headers
82− Just h -> Header h `HCons` buildHeadersTo headers
81+ Right h -> Header h `HCons` buildHeadersTo headers
84-- * Getting
83-- * Getting