on master help sign in
Merge pull request #669 from phadej/json-with-charset

Change JSON content type to add the charset

commit484bc9cb64d3a694393179bf79b48382c5005930 authorOleg Grenrus <oleg.grenrus@iki.fi> dateWed 18 Jan 2017, 13:48 (10 years ago) parent6d0aa927793b52
4 files changed+14−6
servant-server/test/Servant/ServerSpec.hs+1−1 servant/CHANGELOG.md+6 servant/src/Servant/API/ContentTypes.hs+3−1 servant/test/Servant/API/ContentTypesSpec.hs+4−4
servant-server/test/Servant/ServerSpec.hs+1−1
@@ -173,7 +173,7 @@ verbSpec = describe "Servant.API.Verb" $ do
173173 it "sets the Content-Type header" $ do
174174 response <- THW.request method "" [] ""
175175 liftIO $ simpleHeaders response `shouldContain`
176− [("Content-Type", "application/json")]
176+ [("Content-Type", "application/json;charset=utf-8")]
177177
178178 test "GET 200" get200 methodGet 200
179179 test "POST 210" post210 methodPost 210
servant/CHANGELOG.md+6
@@ -12,6 +12,12 @@
1212 ([#345](https://github.com/haskell-servant/servant/pull/345))
1313 ([#305](https://github.com/haskell-servant/servant/issues/305))
1414
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+
15210.9.1
1622------
1723
servant/src/Servant/API/ContentTypes.hs+3−1
@@ -130,7 +130,9 @@ class Accept ctype where
130130
131131-- | @application/json@
132132instance Accept JSON where
133− contentType _ = "application" M.// "json"
133+ contentTypes _ =
134+ "application" M.// "json" M./: ("charset", "utf-8") NE.:|
135+ [ "application" M.// "json" ]
134136
135137-- | @application/x-www-form-urlencoded@
136138instance Accept FormUrlEncoded where
servant/test/Servant/API/ContentTypesSpec.hs+4−4
@@ -115,21 +115,21 @@ spec = describe "Servant.API.ContentTypes" $ do
115115
116116 it "returns the Content-Type as the first element of the tuple" $ do
117117 handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (3 :: Int)
118− `shouldSatisfy` ((== "application/json") . fst . fromJust)
118+ `shouldSatisfy` ((== "application/json;charset=utf-8") . fst . fromJust)
119119 handleAcceptH (Proxy :: Proxy '[PlainText, JSON]) "application/json" (3 :: Int)
120− `shouldSatisfy` ((== "application/json") . fst . fromJust)
120+ `shouldSatisfy` ((== "application/json;charset=utf-8") . fst . fromJust)
121121 handleAcceptH (Proxy :: Proxy '[PlainText, JSON, OctetStream])
122122 "application/octet-stream" ("content" :: ByteString)
123123 `shouldSatisfy` ((== "application/octet-stream") . fst . fromJust)
124124
125125 it "returns the appropriately serialized representation" $ do
126126 property $ \x -> handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (x :: SomeData)
127− == Just ("application/json", encode x)
127+ == Just ("application/json;charset=utf-8", encode x)
128128
129129 it "respects the Accept spec ordering" $ do
130130 let highest a b c = maximumBy (compare `on` snd)
131131 [ ("application/octet-stream", a)
132− , ("application/json", b)
132+ , ("application/json;charset=utf-8", b)
133133 , ("text/plain;charset=utf-8", c)
134134 ]
135135 let acceptH a b c = addToAccept (Proxy :: Proxy OctetStream) a $