From b858626e177317cc0c2469424498ed54c5f027c4 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Sun, 13 Mar 2016 14:21:56 -0700 Subject: [PATCH] For correctness include charset=utf-8 in responses --- src/PostgREST/ApiRequest.hs | 4 ++-- src/PostgREST/App.hs | 2 +- test/Feature/AuthSpec.hs | 4 ++-- test/Feature/InsertSpec.hs | 10 +++++----- test/Feature/QuerySpec.hs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/PostgREST/ApiRequest.hs b/src/PostgREST/ApiRequest.hs index f2c1815b3..92be95859 100644 --- a/src/PostgREST/ApiRequest.hs +++ b/src/PostgREST/ApiRequest.hs @@ -41,8 +41,8 @@ data PreferRepresentation = Full | HeadersOnly | None deriving Eq -- route responses and upload payloads data ContentType = ApplicationJSON | TextCSV deriving Eq instance Show ContentType where - show ApplicationJSON = "application/json" - show TextCSV = "text/csv" + show ApplicationJSON = "application/json; charset=utf-8" + show TextCSV = "text/csv; charset=utf-8" {-| Describes what the user wants to do. This data type is a diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index 44672e09f..752bcc3c3 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -249,7 +249,7 @@ contentRangeH frm to total = fromInRange = frm <= to jsonH :: Header -jsonH = (hContentType, "application/json") +jsonH = (hContentType, "application/json; charset=utf-8") formatRelationError :: Text -> Text formatRelationError = formatGeneralError diff --git a/test/Feature/AuthSpec.hs b/test/Feature/AuthSpec.hs index 55e05efab..5181f8ec9 100644 --- a/test/Feature/AuthSpec.hs +++ b/test/Feature/AuthSpec.hs @@ -21,7 +21,7 @@ spec = describe "authorization" $ do `shouldRespondWith` ResponseMatcher { matchBody = Just [json| {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicG9zdGdyZXN0X3Rlc3RfYXV0aG9yIiwiaWQiOiJqZG9lIn0.y4vZuu1dDdwAl0-S00MCRWRYMlJ5YAMSir6Es6WtWx0"} |] , matchStatus = 200 - , matchHeaders = ["Content-Type" <:> "application/json"] + , matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8"] } it "sql functions can encode custom and standard claims" $ @@ -29,7 +29,7 @@ spec = describe "authorization" $ do `shouldRespondWith` ResponseMatcher { matchBody = Just [json| {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmdW4iLCJqdGkiOiJmb28iLCJuYmYiOjEzMDA4MTkzODAsImV4cCI6MTMwMDgxOTM4MCwiaHR0cDovL3Bvc3RncmVzdC5jb20vZm9vIjp0cnVlLCJpc3MiOiJqb2UiLCJyb2xlIjoicG9zdGdyZXN0X3Rlc3QiLCJpYXQiOjEzMDA4MTkzODAsImF1ZCI6ImV2ZXJ5b25lIn0._tQCF79-ZZGMlLktd3csM_bVaiMg7A8YvIb6K2hcu5w"} |] , matchStatus = 200 - , matchHeaders = ["Content-Type" <:> "application/json"] + , matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8"] } it "sql functions can read custom and standard claims variables" $ do diff --git a/test/Feature/InsertSpec.hs b/test/Feature/InsertSpec.hs index c157b84f6..106242a89 100644 --- a/test/Feature/InsertSpec.hs +++ b/test/Feature/InsertSpec.hs @@ -42,7 +42,7 @@ spec = do } |] `shouldRespondWith` ResponseMatcher { matchBody = Just [str|{"integer":14,"varchar":"testing!"}|] , matchStatus = 201 - , matchHeaders = ["Content-Type" <:> "application/json"] + , matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8"] } it "includes related data after insert" $ @@ -50,7 +50,7 @@ spec = do [str|{"id":6,"name":"New Project","client_id":2}|] `shouldRespondWith` ResponseMatcher { matchBody = Just [str|{"id":6,"name":"New Project","clients":{"id":2,"name":"Apple"}}|] , matchStatus = 201 - , matchHeaders = ["Content-Type" <:> "application/json", "Location" <:> "/projects?id=eq.6"] + , matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8", "Location" <:> "/projects?id=eq.6"] } @@ -184,7 +184,7 @@ spec = do `shouldRespondWith` ResponseMatcher { matchBody = Just inserted , matchStatus = 201 - , matchHeaders = ["Content-Type" <:> "text/csv"] + , matchHeaders = ["Content-Type" <:> "text/csv; charset=utf-8"] } -- p <- request methodPost "/menagerie" [("Content-Type", "text/csv")] -- [str|integer,double,varchar,boolean,date,money,enum @@ -203,7 +203,7 @@ spec = do `shouldRespondWith` ResponseMatcher { matchBody = Just "a,b\nbar,baz" , matchStatus = 201 - , matchHeaders = ["Content-Type" <:> "text/csv", + , matchHeaders = ["Content-Type" <:> "text/csv; charset=utf-8", "Location" <:> "/no_pk?a=eq.bar&b=eq.baz"] } @@ -225,7 +225,7 @@ spec = do `shouldRespondWith` ResponseMatcher { matchBody = Just "a,b\n,foo" , matchStatus = 201 - , matchHeaders = ["Content-Type" <:> "text/csv", + , matchHeaders = ["Content-Type" <:> "text/csv; charset=utf-8", "Location" <:> "/no_pk?a=is.null&b=eq.foo"] } diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 0d0f71a1d..71b353187 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -337,7 +337,7 @@ spec = do `shouldRespondWith` ResponseMatcher { matchBody = Just "k,extra\nxyyx,u\nxYYx,v" , matchStatus = 200 - , matchHeaders = ["Content-Type" <:> "text/csv"] + , matchHeaders = ["Content-Type" <:> "text/csv; charset=utf-8"] } describe "Canonical location" $ do