diff --git a/CHANGELOG.md b/CHANGELOG.md index d05d0d96f..496a60282 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #1473, Fix overloaded computed columns on RPC - @wolfgangwalther - #1471, Fix POST, PATCH, DELETE with ?select= and return=minimal and PATCH with empty body - @wolfgangwalther - #1500, Fix missing `openapi-server-proxy-uri` config option - @steve-chavez +- #1508, Fix `Content-Profile` not working for POST RPC - @steve-chavez ## [7.0.0] - 2020-04-03 diff --git a/Makefile b/Makefile index e2474c824..2ef0d2237 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ check: lint style test clean: prompt-clean stack clean --full +# For running these you'll need to install hlint and stylish-haskell first. Run: +# stack install hlint stylish-haskell lint: git ls-files | grep '\.l\?hs$$' | xargs stack exec -- hlint -X QuasiQuotes -X NoPatternSynonyms "$$@" diff --git a/src/PostgREST/ApiRequest.hs b/src/PostgREST/ApiRequest.hs index 8b8a10658..471d6d5a2 100644 --- a/src/PostgREST/ApiRequest.hs +++ b/src/PostgREST/ApiRequest.hs @@ -220,9 +220,9 @@ userApiRequest confSchemas rootSpec req reqBody profile | length confSchemas <= 1 -- only enable content negotiation by profile when there are multiple schemas specified in the config = Nothing - | action `elem` [ActionCreate, ActionUpdate, ActionSingleUpsert, ActionDelete] -- POST/PATCH/PUT/DELETE don't use the same header as per the spec + | action `elem` [ActionCreate, ActionUpdate, ActionSingleUpsert, ActionDelete, ActionInvoke InvPost] -- POST/PATCH/PUT/DELETE don't use the same header as per the spec = Just $ maybe defaultSchema toS $ lookupHeader "Content-Profile" - | action `elem` [ActionRead True, ActionRead False, ActionInvoke InvGet, ActionInvoke InvHead, ActionInvoke InvPost, + | action `elem` [ActionRead True, ActionRead False, ActionInvoke InvGet, ActionInvoke InvHead, ActionInspect False, ActionInspect True, ActionInfo] = Just $ maybe defaultSchema toS $ lookupHeader "Accept-Profile" | otherwise = Nothing diff --git a/test/Feature/MultipleSchemaSpec.hs b/test/Feature/MultipleSchemaSpec.hs index ffe2a6592..efc704726 100644 --- a/test/Feature/MultipleSchemaSpec.hs +++ b/test/Feature/MultipleSchemaSpec.hs @@ -146,6 +146,18 @@ spec actualPgVersion = , matchHeaders = [matchContentTypeJson, "Content-Profile" <:> "v2"] } + it "succeeds in calling the v2 schema proc with POST by using Content-Profile" $ + request methodPost "/rpc/get_parents_below?select=id,name" [("Content-Profile", "v2")] + [json|{"id": "6"}|] + `shouldRespondWith` + [json| [ + {"id":3,"name":"parent v2-3"}, + {"id":4,"name":"parent v2-4"}]|] + { + matchStatus = 200 + , matchHeaders = [matchContentTypeJson, "Content-Profile" <:> "v2"] + } + context "Modifying tables on different schemas" $ do it "succeeds in patching on the v1 schema and returning its parent" $ request methodPatch "/children?select=name,parent(name)&id=eq.1" [("Content-Profile", "v1"), ("Prefer", "return=representation")]