on master help sign in
Merge pull request #669 from phadej/json-with-charset
484bc9cOleg Grenrus
servant-server/test/Servant/ServerSpec.hs+1−1
@@ -173,7 +173,7 @@ verbSpec = describe "Servant.API.Verb" $ do
173 it "sets the Content-Type header" $ do
173 it "sets the Content-Type header" $ do
174 response <- THW.request method "" [] ""
174 response <- THW.request method "" [] ""
175 liftIO $ simpleHeaders response `shouldContain`
175 liftIO $ simpleHeaders response `shouldContain`
176− [("Content-Type", "application/json")]
176+ [("Content-Type", "application/json;charset=utf-8")]
177
177
178 test "GET 200" get200 methodGet 200
178 test "GET 200" get200 methodGet 200
179 test "POST 210" post210 methodPost 210
179 test "POST 210" post210 methodPost 210
servant/CHANGELOG.md+6
@@ -12,6 +12,12 @@
12 ([#345](https://github.com/haskell-servant/servant/pull/345))
12 ([#345](https://github.com/haskell-servant/servant/pull/345))
13 ([#305](https://github.com/haskell-servant/servant/issues/305))
13 ([#305](https://github.com/haskell-servant/servant/issues/305))
14
14
15+* Default JSON content type change to `application/json;charset=utf-8`.
16+ ([#263](https://github.com/haskell-servant/servant/issues/263))
17+ Related browser bugs:
18+ [Chromium](https://bugs.chromium.org/p/chromium/issues/detail?id=438464) and
19+ [Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=918742)
20+
150.9.1
210.9.1
16------
22------
17
23
servant/src/Servant/API/ContentTypes.hs+3−1
@@ -130,7 +130,9 @@ class Accept ctype where
130
130
131-- | @application/json@
131-- | @application/json@
132instance Accept JSON where
132instance Accept JSON where
133+ contentTypes _ =
134+ "application" M.// "json" M./: ("charset", "utf-8") NE.:|
133− contentType _ = "application" M.// "json"
135+ [ "application" M.// "json" ]
134
136
135-- | @application/x-www-form-urlencoded@
137-- | @application/x-www-form-urlencoded@
136instance Accept FormUrlEncoded where
138instance Accept FormUrlEncoded where
servant/test/Servant/API/ContentTypesSpec.hs+4−4
@@ -115,21 +115,21 @@ spec = describe "Servant.API.ContentTypes" $ do
115
115
116 it "returns the Content-Type as the first element of the tuple" $ do
116 it "returns the Content-Type as the first element of the tuple" $ do
117 handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (3 :: Int)
117 handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (3 :: Int)
118− `shouldSatisfy` ((== "application/json") . fst . fromJust)
118+ `shouldSatisfy` ((== "application/json;charset=utf-8") . fst . fromJust)
119 handleAcceptH (Proxy :: Proxy '[PlainText, JSON]) "application/json" (3 :: Int)
119 handleAcceptH (Proxy :: Proxy '[PlainText, JSON]) "application/json" (3 :: Int)
120− `shouldSatisfy` ((== "application/json") . fst . fromJust)
120+ `shouldSatisfy` ((== "application/json;charset=utf-8") . fst . fromJust)
121 handleAcceptH (Proxy :: Proxy '[PlainText, JSON, OctetStream])
121 handleAcceptH (Proxy :: Proxy '[PlainText, JSON, OctetStream])
122 "application/octet-stream" ("content" :: ByteString)
122 "application/octet-stream" ("content" :: ByteString)
123 `shouldSatisfy` ((== "application/octet-stream") . fst . fromJust)
123 `shouldSatisfy` ((== "application/octet-stream") . fst . fromJust)
124
124
125 it "returns the appropriately serialized representation" $ do
125 it "returns the appropriately serialized representation" $ do
126 property $ \x -> handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (x :: SomeData)
126 property $ \x -> handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (x :: SomeData)
127− == Just ("application/json", encode x)
127+ == Just ("application/json;charset=utf-8", encode x)
128
128
129 it "respects the Accept spec ordering" $ do
129 it "respects the Accept spec ordering" $ do
130 let highest a b c = maximumBy (compare `on` snd)
130 let highest a b c = maximumBy (compare `on` snd)
131 [ ("application/octet-stream", a)
131 [ ("application/octet-stream", a)
132− , ("application/json", b)
132+ , ("application/json;charset=utf-8", b)
133 , ("text/plain;charset=utf-8", c)
133 , ("text/plain;charset=utf-8", c)
134 ]
134 ]
135 let acceptH a b c = addToAccept (Proxy :: Proxy OctetStream) a $
135 let acceptH a b c = addToAccept (Proxy :: Proxy OctetStream) a $