From 7278507c420f65f8a0237bba3c54c1a6b4d007dd Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Sun, 21 Aug 2016 15:26:00 -0700 Subject: [PATCH] Use comma rather than semicolon to split header values (#698) --- CHANGELOG.md | 1 + src/PostgREST/ApiRequest.hs | 2 +- src/PostgREST/OpenAPI.hs | 2 +- test/Feature/InsertSpec.hs | 8 ++++---- test/Feature/QuerySpec.hs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02476bbe8..c1e3e897a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Use HTTP 400 for raise\_exception - @begriffs - Remove non-OpenAPI schema description - @begriffs +- Use comma rather than semicolon to separate Prefer header values - @begriffs ## [0.3.2.0] - 2016-06-10 diff --git a/src/PostgREST/ApiRequest.hs b/src/PostgREST/ApiRequest.hs index d8b1ee155..ef291ce02 100644 --- a/src/PostgREST/ApiRequest.hs +++ b/src/PostgREST/ApiRequest.hs @@ -176,7 +176,7 @@ userApiRequest schema req reqBody = hasPrefer val = any (\(h,v) -> h == "Prefer" && val `elem` split v) hdrs where split :: BS.ByteString -> [Text] - split = map T.strip . T.split (==';') . toS + split = map T.strip . T.split (==',') . toS singular = hasPrefer "plurality=singular" representation | hasPrefer "return=representation" = Full diff --git a/src/PostgREST/OpenAPI.hs b/src/PostgREST/OpenAPI.hs index 3803dd8b3..af2167f5e 100644 --- a/src/PostgREST/OpenAPI.hs +++ b/src/PostgREST/OpenAPI.hs @@ -164,7 +164,7 @@ makeGetParams cs = makePostParams :: Text -> [Param] makePostParams tn = - [ makePreferParam ["return=representation", "return=representation;plurality=singular", + [ makePreferParam ["return=representation", "return=representation,plurality=singular", "return=minimal", "return=none"] , (mempty :: Param) & name .~ "body" diff --git a/test/Feature/InsertSpec.hs b/test/Feature/InsertSpec.hs index 4622e6c47..e36860cc5 100644 --- a/test/Feature/InsertSpec.hs +++ b/test/Feature/InsertSpec.hs @@ -403,7 +403,7 @@ spec = do _ <- post "/addresses" [json| { id: 97, address: "A Street" } |] p <- request methodPatch "/addresses?id=eq.97" - [("Prefer", "return=representation;plurality=singular")] + [("Prefer", "return=representation,plurality=singular")] [json| { address: "B Street" } |] liftIO $ simpleBody p `shouldBe` [str|{"id":97,"address":"B Street"}|] it "raises an error when attempting to update multiple entities with plurality=singular" $ do @@ -411,19 +411,19 @@ spec = do _ <- post "/addresses" [json| { id: 99, address: "yyy" } |] p <- request methodPatch "/addresses?id=gt.0" - [("Prefer", "return=representation;plurality=singular")] + [("Prefer", "return=representation,plurality=singular")] [json| { address: "zzz" } |] liftIO $ simpleStatus p `shouldBe` status400 it "can provide a singular representation when creating one entity" $ do p <- request methodPost "/addresses" - [("Prefer", "return=representation;plurality=singular")] + [("Prefer", "return=representation,plurality=singular")] [json| [ { id: 100, address: "xxx" } ] |] liftIO $ simpleBody p `shouldBe` [str|{"id":100,"address":"xxx"}|] it "raises an error when attempting to create multiple entities with plurality=singular" $ do p <- request methodPost "/addresses" - [("Prefer", "return=representation;plurality=singular")] + [("Prefer", "return=representation,plurality=singular")] [json| [ { id: 100, address: "xxx" }, { id: 101, address: "xxx" } ] |] liftIO $ simpleStatus p `shouldBe` status400 diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 371076093..b5b9092f9 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -286,7 +286,7 @@ spec = do } it "can combine multiple prefer values" $ - request methodGet "/items?id=eq.5" [("Prefer","plurality=singular ; future=new; count=none")] "" + request methodGet "/items?id=eq.5" [("Prefer","plurality=singular , future=new, count=none")] "" `shouldRespondWith` ResponseMatcher { matchBody = Just [json| {"id":5} |] , matchStatus = 200