diff --git a/CHANGELOG.md b/CHANGELOG.md index 85408341f..375cfc8d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #2145, Fix accessing json array fields with -> and ->> in ?select= and ?order=. - @wolfgangwalther - #2153, Fix --dump-schema running with a wrong PG version. - @wolfgangwalther - #2042, Keep working when EMFILE(Too many open files) is reached. - @steve-chavez + - #2147, Ignore `Content-Type` headers for `GET` requests when calling RPCs. Previously, `GET` without parameters, but with `Content-Type: text/plain` or `Content-Type: application/octet-stream` would fail with `404 Not Found`, even if a function without arguments was available. + - ``` ### Changed diff --git a/src/PostgREST/Request/ApiRequest.hs b/src/PostgREST/Request/ApiRequest.hs index cd5271965..00e076d1b 100644 --- a/src/PostgREST/Request/ApiRequest.hs +++ b/src/PostgREST/Request/ApiRequest.hs @@ -505,7 +505,7 @@ findProc qi argumentsKeys paramsAsSingleObject allProcs contentType isInvPost = then length params == 1 && (ppType <$> headMay params) `elem` [Just "json", Just "jsonb"] -- If the function has no parameters, the arguments keys must be empty as well else if null params - then null argumentsKeys && contentType `notElem` [CTTextPlain, CTOctetStream] + then null argumentsKeys && not (isInvPost && contentType `elem` [CTTextPlain, CTOctetStream]) -- A function has optional and required parameters. Optional parameters have a default value and -- don't require arguments for the function to be executed, required parameters must have an argument present. else case L.partition ppReq params of diff --git a/test/spec/Feature/RpcSpec.hs b/test/spec/Feature/RpcSpec.hs index 9c861b7f5..a225973e3 100644 --- a/test/spec/Feature/RpcSpec.hs +++ b/test/spec/Feature/RpcSpec.hs @@ -1232,6 +1232,16 @@ spec actualPgVersion = let respBody = simpleBody r respBody `shouldBe` file + it "should call the function with no parameters and not fallback to the single unnamed parameter function when using GET with Content-Type headers" $ do + request methodGet "/rpc/overloaded_unnamed_param" [("Content-Type", "text/plain")] "" + `shouldRespondWith` + [json| 1|] + { matchStatus = 200 } + request methodGet "/rpc/overloaded_unnamed_param" [("Content-Type", "application/octet-stream")] "" + `shouldRespondWith` + [json| 1|] + { matchStatus = 200 } + it "should fail to fallback to any single unnamed parameter function when using an unsupported Content-Type header" $ do request methodPost "/rpc/overloaded_unnamed_param" [("Content-Type", "text/csv")]