Use comma rather than semicolon to split header values (#698)

This commit is contained in:
Joe Nelson
2016-08-21 15:26:00 -07:00
committed by GitHub
parent 6f737056a2
commit 7278507c42
5 changed files with 8 additions and 7 deletions
+1
View File
@@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed ### Changed
- Use HTTP 400 for raise\_exception - @begriffs - Use HTTP 400 for raise\_exception - @begriffs
- Remove non-OpenAPI schema description - @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 ## [0.3.2.0] - 2016-06-10
+1 -1
View File
@@ -176,7 +176,7 @@ userApiRequest schema req reqBody =
hasPrefer val = any (\(h,v) -> h == "Prefer" && val `elem` split v) hdrs hasPrefer val = any (\(h,v) -> h == "Prefer" && val `elem` split v) hdrs
where where
split :: BS.ByteString -> [Text] split :: BS.ByteString -> [Text]
split = map T.strip . T.split (==';') . toS split = map T.strip . T.split (==',') . toS
singular = hasPrefer "plurality=singular" singular = hasPrefer "plurality=singular"
representation representation
| hasPrefer "return=representation" = Full | hasPrefer "return=representation" = Full
+1 -1
View File
@@ -164,7 +164,7 @@ makeGetParams cs =
makePostParams :: Text -> [Param] makePostParams :: Text -> [Param]
makePostParams tn = makePostParams tn =
[ makePreferParam ["return=representation", "return=representation;plurality=singular", [ makePreferParam ["return=representation", "return=representation,plurality=singular",
"return=minimal", "return=none"] "return=minimal", "return=none"]
, (mempty :: Param) , (mempty :: Param)
& name .~ "body" & name .~ "body"
+4 -4
View File
@@ -403,7 +403,7 @@ spec = do
_ <- post "/addresses" [json| { id: 97, address: "A Street" } |] _ <- post "/addresses" [json| { id: 97, address: "A Street" } |]
p <- request methodPatch p <- request methodPatch
"/addresses?id=eq.97" "/addresses?id=eq.97"
[("Prefer", "return=representation;plurality=singular")] [("Prefer", "return=representation,plurality=singular")]
[json| { address: "B Street" } |] [json| { address: "B Street" } |]
liftIO $ simpleBody p `shouldBe` [str|{"id":97,"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 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" } |] _ <- post "/addresses" [json| { id: 99, address: "yyy" } |]
p <- request methodPatch p <- request methodPatch
"/addresses?id=gt.0" "/addresses?id=gt.0"
[("Prefer", "return=representation;plurality=singular")] [("Prefer", "return=representation,plurality=singular")]
[json| { address: "zzz" } |] [json| { address: "zzz" } |]
liftIO $ simpleStatus p `shouldBe` status400 liftIO $ simpleStatus p `shouldBe` status400
it "can provide a singular representation when creating one entity" $ do it "can provide a singular representation when creating one entity" $ do
p <- request methodPost p <- request methodPost
"/addresses" "/addresses"
[("Prefer", "return=representation;plurality=singular")] [("Prefer", "return=representation,plurality=singular")]
[json| [ { id: 100, address: "xxx" } ] |] [json| [ { id: 100, address: "xxx" } ] |]
liftIO $ simpleBody p `shouldBe` [str|{"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 it "raises an error when attempting to create multiple entities with plurality=singular" $ do
p <- request methodPost p <- request methodPost
"/addresses" "/addresses"
[("Prefer", "return=representation;plurality=singular")] [("Prefer", "return=representation,plurality=singular")]
[json| [ { id: 100, address: "xxx" }, { id: 101, address: "xxx" } ] |] [json| [ { id: 100, address: "xxx" }, { id: 101, address: "xxx" } ] |]
liftIO $ simpleStatus p `shouldBe` status400 liftIO $ simpleStatus p `shouldBe` status400
+1 -1
View File
@@ -286,7 +286,7 @@ spec = do
} }
it "can combine multiple prefer values" $ 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 { `shouldRespondWith` ResponseMatcher {
matchBody = Just [json| {"id":5} |] matchBody = Just [json| {"id":5} |]
, matchStatus = 200 , matchStatus = 200