diff --git a/CHANGELOG.md b/CHANGELOG.md index c1637d3fb..d1c42dd7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #3149, Misleading "Starting PostgREST.." logs on schema cache reloading - @steve-chavez - #2815, Build static executable with GSSAPI support - @wolfgangwalther - #3205, Fix wrong subquery error returning a status of 400 Bad Request - @steve-chavez + - #3224, Return status code 406 for non-accepted media type instead of code 415 - @wolfgangwalther ### Deprecated diff --git a/src/PostgREST/Error.hs b/src/PostgREST/Error.hs index e1fb40e13..2a7b5cb73 100644 --- a/src/PostgREST/Error.hs +++ b/src/PostgREST/Error.hs @@ -65,7 +65,7 @@ instance PgrstError ApiRequestError where status AggregatesNotAllowed{} = HTTP.status400 status AmbiguousRelBetween{} = HTTP.status300 status AmbiguousRpc{} = HTTP.status300 - status MediaTypeError{} = HTTP.status415 + status MediaTypeError{} = HTTP.status406 status InvalidBody{} = HTTP.status400 status InvalidFilters = HTTP.status405 status InvalidPreferences{} = HTTP.status400 diff --git a/test/spec/Feature/OpenApi/OpenApiSpec.hs b/test/spec/Feature/OpenApi/OpenApiSpec.hs index e5b2e72b8..eae5fef3e 100644 --- a/test/spec/Feature/OpenApi/OpenApiSpec.hs +++ b/test/spec/Feature/OpenApi/OpenApiSpec.hs @@ -30,15 +30,15 @@ spec actualPgVersion = describe "OpenAPI" $ do , matchHeaders = ["Content-Type" <:> "application/openapi+json; charset=utf-8"] } - it "should respond to openapi request on none root path with 415" $ + it "should respond to openapi request on none root path with 406" $ request methodGet "/items" (acceptHdrs "application/openapi+json") "" - `shouldRespondWith` 415 + `shouldRespondWith` 406 - it "should respond to openapi request with unsupported media type with 415" $ + it "should respond to openapi request with unsupported media type with 406" $ request methodGet "/" (acceptHdrs "text/csv") "" - `shouldRespondWith` 415 + `shouldRespondWith` 406 it "includes postgrest.org current version api docs" $ do r <- simpleBody <$> get "/" diff --git a/test/spec/Feature/Query/CustomMediaSpec.hs b/test/spec/Feature/Query/CustomMediaSpec.hs index c5c178604..73b98446e 100644 --- a/test/spec/Feature/Query/CustomMediaSpec.hs +++ b/test/spec/Feature/Query/CustomMediaSpec.hs @@ -31,7 +31,7 @@ spec = describe "custom media types" $ do request methodGet "/lines" (acceptHdrs "text/plain") "" `shouldRespondWith` [json| {"code":"PGRST107","details":null,"hint":null,"message":"None of these media types are available: text/plain"} |] - { matchStatus = 415 + { matchStatus = 406 , matchHeaders = [matchContentTypeJson] } @@ -115,7 +115,7 @@ spec = describe "custom media types" $ do [json| {"code":"PGRST107","details":null,"hint":null,"message":"None of these media types are available: text/xml"} |] - { matchStatus = 415 + { matchStatus = 406 , matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8"] } @@ -140,7 +140,7 @@ spec = describe "custom media types" $ do "" `shouldRespondWith` [json|{"code":"PGRST107","details":null,"hint":null,"message":"None of these media types are available: text/plain"}|] - { matchStatus = 415 + { matchStatus = 406 , matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8"] } @@ -156,7 +156,7 @@ spec = describe "custom media types" $ do (acceptHdrs "application/octet-stream") "" `shouldRespondWith` [json| {"code":"PGRST107","details":null,"hint":null,"message":"None of these media types are available: application/octet-stream"} |] - { matchStatus = 415 } + { matchStatus = 406 } -- TODO SOH (start of heading) is being added to results it "works if there's an anyelement aggregate defined" $ do @@ -279,7 +279,7 @@ spec = describe "custom media types" $ do } request methodGet "/rpc/ret_some_mt" (acceptHdrs "text/csv") "" - `shouldRespondWith` 415 + `shouldRespondWith` 406 context "on tables" $ do it "returns application/json for */* if not explicitly set" $ do diff --git a/test/spec/Feature/Query/PlanSpec.hs b/test/spec/Feature/Query/PlanSpec.hs index 704fe877e..de63dcceb 100644 --- a/test/spec/Feature/Query/PlanSpec.hs +++ b/test/spec/Feature/Query/PlanSpec.hs @@ -463,12 +463,12 @@ disabledSpec = it "doesn't work if db-plan-enabled=false(the default)" $ do request methodGet "/projects?id=in.(1,2,3)" (acceptHdrs "application/vnd.pgrst.plan") "" - `shouldRespondWith` 415 + `shouldRespondWith` 406 request methodGet "/rpc/getallprojects?id=in.(1,2,3)" (acceptHdrs "application/vnd.pgrst.plan") "" - `shouldRespondWith` 415 + `shouldRespondWith` 406 request methodDelete "/projects?id=in.(1,2,3)" (acceptHdrs "application/vnd.pgrst.plan") "" - `shouldRespondWith` 415 + `shouldRespondWith` 406 diff --git a/test/spec/Feature/Query/QuerySpec.hs b/test/spec/Feature/Query/QuerySpec.hs index 073cb4824..e1ce20aa1 100644 --- a/test/spec/Feature/Query/QuerySpec.hs +++ b/test/spec/Feature/Query/QuerySpec.hs @@ -939,12 +939,12 @@ spec actualPgVersion = do } describe "Accept headers" $ do - it "should respond an unknown accept type with 415" $ + it "should respond an unknown accept type with 406" $ request methodGet "/simple_pk" (acceptHdrs "text/unknowntype") "" `shouldRespondWith` [json|{"message":"None of these media types are available: text/unknowntype","code":"PGRST107","details":null,"hint":null}|] - { matchStatus = 415 + { matchStatus = 406 , matchHeaders = [matchContentTypeJson] } diff --git a/test/spec/Feature/Query/RpcSpec.hs b/test/spec/Feature/Query/RpcSpec.hs index fc1461579..4887e8fac 100644 --- a/test/spec/Feature/Query/RpcSpec.hs +++ b/test/spec/Feature/Query/RpcSpec.hs @@ -656,10 +656,10 @@ spec actualPgVersion = it "rejects unknown content type even if payload is good" $ do request methodPost "/rpc/sayhello" (acceptHdrs "audio/mpeg3") [json| { "name": "world" } |] - `shouldRespondWith` 415 + `shouldRespondWith` 406 request methodGet "/rpc/sayhello?name=world" (acceptHdrs "audio/mpeg3") "" - `shouldRespondWith` 415 + `shouldRespondWith` 406 it "rejects malformed json payload" $ do p <- request methodPost "/rpc/sayhello" (acceptHdrs "application/json") "sdfsdf" diff --git a/test/spec/fixtures/schema.sql b/test/spec/fixtures/schema.sql index d086c6142..f7198bf2f 100644 --- a/test/spec/fixtures/schema.sql +++ b/test/spec/fixtures/schema.sql @@ -3714,7 +3714,7 @@ begin perform set_config('response.headers', json_build_array(json_build_object('Content-Type', 'app/groucho'))::text, true); resp := 'groucho'; else - raise sqlstate 'PT415' using message = 'Unsupported Media Type'; + raise sqlstate 'PT406' using message = 'Not Acceptable'; end case; return resp; end; $$ language plpgsql;