From 9b5a564f3c151c699a6ee16c7e0dfc9564fcc1f8 Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Fri, 2 Sep 2016 23:14:45 +1000 Subject: [PATCH] Remove dependency on bytestring-conversion --- servant/servant.cabal | 1 - servant/src/Servant/API/ResponseHeaders.hs | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/servant/servant.cabal b/servant/servant.cabal index 0f308995..56a2cc6e 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -54,7 +54,6 @@ library , aeson >= 0.7 && < 1.1 , attoparsec >= 0.12 && < 0.14 , bytestring >= 0.10 && < 0.11 - , bytestring-conversion >= 0.3 && < 0.4 , case-insensitive >= 1.2 && < 1.3 , http-api-data >= 0.1 && < 0.3 , http-media >= 0.4 && < 0.7 diff --git a/servant/src/Servant/API/ResponseHeaders.hs b/servant/src/Servant/API/ResponseHeaders.hs index d70f78b5..1ddba9d0 100644 --- a/servant/src/Servant/API/ResponseHeaders.hs +++ b/servant/src/Servant/API/ResponseHeaders.hs @@ -31,9 +31,8 @@ module Servant.API.ResponseHeaders ) where import Data.ByteString.Char8 as BS (pack, unlines, init) -import Data.ByteString.Conversion (--ToByteString, toByteString', - FromByteString, fromByteString) -import Web.HttpApiData (ToHttpApiData,toHeader) +import Web.HttpApiData (ToHttpApiData,toHeader + ,FromHttpApiData,parseHeader) import qualified Data.CaseInsensitive as CI import Data.Proxy import GHC.TypeLits (KnownSymbol, symbolVal) @@ -69,17 +68,17 @@ class BuildHeadersTo hs where instance OVERLAPPING_ BuildHeadersTo '[] where 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 headers = let wantedHeader = CI.mk . pack $ symbolVal (Proxy :: Proxy h) matching = snd <$> filter (\(h, _) -> h == wantedHeader) headers in case matching of [] -> MissingHeader `HCons` buildHeadersTo headers - xs -> case fromByteString (BS.init $ BS.unlines xs) of - Nothing -> UndecodableHeader (BS.init $ BS.unlines xs) + xs -> case parseHeader (BS.init $ BS.unlines xs) of + Left _err -> UndecodableHeader (BS.init $ BS.unlines xs) `HCons` buildHeadersTo headers - Just h -> Header h `HCons` buildHeadersTo headers + Right h -> Header h `HCons` buildHeadersTo headers -- * Getting