Remove dependency on bytestring-conversion
This commit is contained in:
parent
a1b23018f9
commit
9b5a564f3c
2 changed files with 6 additions and 8 deletions
|
@ -54,7 +54,6 @@ library
|
||||||
, aeson >= 0.7 && < 1.1
|
, aeson >= 0.7 && < 1.1
|
||||||
, attoparsec >= 0.12 && < 0.14
|
, attoparsec >= 0.12 && < 0.14
|
||||||
, bytestring >= 0.10 && < 0.11
|
, bytestring >= 0.10 && < 0.11
|
||||||
, bytestring-conversion >= 0.3 && < 0.4
|
|
||||||
, case-insensitive >= 1.2 && < 1.3
|
, case-insensitive >= 1.2 && < 1.3
|
||||||
, http-api-data >= 0.1 && < 0.3
|
, http-api-data >= 0.1 && < 0.3
|
||||||
, http-media >= 0.4 && < 0.7
|
, http-media >= 0.4 && < 0.7
|
||||||
|
|
|
@ -31,9 +31,8 @@ module Servant.API.ResponseHeaders
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.ByteString.Char8 as BS (pack, unlines, init)
|
import Data.ByteString.Char8 as BS (pack, unlines, init)
|
||||||
import Data.ByteString.Conversion (--ToByteString, toByteString',
|
import Web.HttpApiData (ToHttpApiData,toHeader
|
||||||
FromByteString, fromByteString)
|
,FromHttpApiData,parseHeader)
|
||||||
import Web.HttpApiData (ToHttpApiData,toHeader)
|
|
||||||
import qualified Data.CaseInsensitive as CI
|
import qualified Data.CaseInsensitive as CI
|
||||||
import Data.Proxy
|
import Data.Proxy
|
||||||
import GHC.TypeLits (KnownSymbol, symbolVal)
|
import GHC.TypeLits (KnownSymbol, symbolVal)
|
||||||
|
@ -69,17 +68,17 @@ class BuildHeadersTo hs where
|
||||||
instance OVERLAPPING_ BuildHeadersTo '[] where
|
instance OVERLAPPING_ BuildHeadersTo '[] where
|
||||||
buildHeadersTo _ = HNil
|
buildHeadersTo _ = HNil
|
||||||
|
|
||||||
instance OVERLAPPABLE_ ( FromByteString v, BuildHeadersTo xs, KnownSymbol h )
|
instance OVERLAPPABLE_ ( FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h )
|
||||||
=> BuildHeadersTo ((Header h v) ': xs) where
|
=> BuildHeadersTo ((Header h v) ': xs) where
|
||||||
buildHeadersTo headers =
|
buildHeadersTo headers =
|
||||||
let wantedHeader = CI.mk . pack $ symbolVal (Proxy :: Proxy h)
|
let wantedHeader = CI.mk . pack $ symbolVal (Proxy :: Proxy h)
|
||||||
matching = snd <$> filter (\(h, _) -> h == wantedHeader) headers
|
matching = snd <$> filter (\(h, _) -> h == wantedHeader) headers
|
||||||
in case matching of
|
in case matching of
|
||||||
[] -> MissingHeader `HCons` buildHeadersTo headers
|
[] -> MissingHeader `HCons` buildHeadersTo headers
|
||||||
xs -> case fromByteString (BS.init $ BS.unlines xs) of
|
xs -> case parseHeader (BS.init $ BS.unlines xs) of
|
||||||
Nothing -> UndecodableHeader (BS.init $ BS.unlines xs)
|
Left _err -> UndecodableHeader (BS.init $ BS.unlines xs)
|
||||||
`HCons` buildHeadersTo headers
|
`HCons` buildHeadersTo headers
|
||||||
Just h -> Header h `HCons` buildHeadersTo headers
|
Right h -> Header h `HCons` buildHeadersTo headers
|
||||||
|
|
||||||
-- * Getting
|
-- * Getting
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue