From 098b5036251408e571b843e4264edfdb7f91bab2 Mon Sep 17 00:00:00 2001 From: Timo von Holtz Date: Tue, 17 Feb 2015 11:56:15 +1100 Subject: [PATCH] Don't send an Accept header if the list of accepted types is empty --- src/Servant/Common/Req.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Servant/Common/Req.hs b/src/Servant/Common/Req.hs index 3832b86d..09ea2b03 100644 --- a/src/Servant/Common/Req.hs +++ b/src/Servant/Common/Req.hs @@ -13,7 +13,7 @@ import Data.Aeson import Data.Aeson.Parser import Data.Aeson.Types import Data.Attoparsec.ByteString -import Data.ByteString.Lazy hiding (pack, filter, map) +import Data.ByteString.Lazy hiding (pack, filter, map, null) import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BSC import Data.String @@ -93,7 +93,8 @@ reqToRequest req (BaseUrl reqScheme reqHost reqPort) = setheaders r = r { requestHeaders = requestHeaders r ++ Prelude.map toProperHeader (headers req) } setAccept r = r { requestHeaders = filter ((/= "Accept") . fst) (requestHeaders r) - ++ [("Accept", BS.intercalate ", " (map renderAccept $ reqAccept req))] } + ++ [("Accept", BS.intercalate ", " (map renderAccept $ reqAccept req)) + | not . null . reqAccept $ req] } renderAccept :: MediaType -> BS.ByteString renderAccept m = BSC.pack (show m) toProperHeader (name, val) =