@@ -13,6 +13,7 @@ import Data.Function (on)
1313import Data.Maybe (isJust, fromJust)
1414import Data.List (maximumBy)
1515import Data.Proxy (Proxy(..))
16+import qualified Data.Text.Lazy as T
1617import Data.String (IsString(..))
1718import Data.String.Conversions (cs)
1819import Network.HTTP.Types (hAccept)
@@ -45,22 +46,22 @@ handleAcceptHSpec = describe "handleAcceptH" $ do
4546
4647 it "should return the Content-Type as the first element of the tuple" $ do
4748 handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (3 :: Int)
48− `shouldSatisfy` ((== "application/json") . fst . fromJust)
49+ `shouldSatisfy` ((== "application/json;charset=utf-8") . fst . fromJust)
4950 handleAcceptH (Proxy :: Proxy '[XML, JSON]) "application/json" (3 :: Int)
50− `shouldSatisfy` ((== "application/json") . fst . fromJust)
51+ `shouldSatisfy` ((== "application/json;charset=utf-8") . fst . fromJust)
5152 handleAcceptH (Proxy :: Proxy '[XML, JSON, HTML]) "text/html" (3 :: Int)
52− `shouldSatisfy` ((== "text/html") . fst . fromJust)
53+ `shouldSatisfy` ((== "text/html;charset=utf-8") . fst . fromJust)
5354
5455 it "should return the appropriately serialized representation" $ do
5556 property $ \x -> handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (x :: Int)
56− == Just ("application/json", encode x)
57+ == Just ("application/json;charset=utf-8", encode x)
5758
5859 it "respects the Accept spec ordering" $
5960 property $ \a b c i -> fst (fromJust $ val a b c i) == (fst $ highest a b c)
6061 where
61− highest a b c = maximumBy (compare `on` snd) [ ("text/html", a)
62− , ("application/json", b)
63− , ("application/xml", c)
62+ highest a b c = maximumBy (compare `on` snd) [ ("text/html;charset=utf-8", a)
63+ , ("application/json;charset=utf-8", b)
64+ , ("application/xml;charset=utf-8", c)
6465 ]
6566 acceptH a b c = addToAccept (Proxy :: Proxy HTML) a $
6667 addToAccept (Proxy :: Proxy JSON) b $
@@ -69,13 +70,13 @@ handleAcceptHSpec = describe "handleAcceptH" $ do
6970 (acceptH a b c) (i :: Int)
7071
7172type ContentTypeApi = "foo" :> Get '[JSON] Int
72− :<|> "bar" :> Get '[JSON, PlainText] Int
73+ :<|> "bar" :> Get '[JSON, PlainText] T.Text
7374
7475contentTypeApi :: Proxy ContentTypeApi
7576contentTypeApi = Proxy
7677
7778contentTypeServer :: Server ContentTypeApi
78−contentTypeServer = return 5 :<|> return 3
79+contentTypeServer = return 5 :<|> return "hi"
7980
8081contentTypeSpec :: Spec
8182contentTypeSpec = do
@@ -88,14 +89,14 @@ contentTypeSpec = do
8889 requestHeaders = [(hAccept, acceptH)] ,
8990 pathInfo = ["bar"]
9091 }
91− assertContentType "text/plain" response
92+ assertContentType "text/plain;charset=utf8" response
9293
9394 it "returns the first content-type if the Accept header is missing" $
9495 flip runSession (serve contentTypeApi contentTypeServer) $ do
9596 response <- Network.Wai.Test.request defaultRequest{
9697 pathInfo = ["bar"]
9798 }
98− assertContentType "application/json" response
99+ assertContentType "application/json;charset=utf8" response
99100
100101 it "returns 406 if it can't serve the requested content-type" $
101102 flip runSession (serve contentTypeApi contentTypeServer) $ do