fix: any handler sets a default application/json
Now it sets application/octet-stream as the generic type.
This commit is contained in:
committed by
Steve Chavez
parent
4fb521cac6
commit
6b9fde59cd
@@ -225,31 +225,30 @@ spec = describe "custom media types" $ do
|
||||
|
||||
context "any media type" $ do
|
||||
context "on functions" $ do
|
||||
-- TODO not correct, it should return the generic "application/octet-stream"
|
||||
it "returns application/json for */* if not explicitly set" $ do
|
||||
request methodGet "/rpc/ret_any_mt" (acceptHdrs "*/*") ""
|
||||
`shouldRespondWith` "any"
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = [matchContentTypeJson]
|
||||
, matchHeaders = ["Content-Type" <:> "application/octet-stream"]
|
||||
}
|
||||
|
||||
it "accepts any media type and sets it as a header" $ do
|
||||
it "accepts any media type and sets the generic octet-stream as content type" $ do
|
||||
request methodGet "/rpc/ret_any_mt" (acceptHdrs "app/bingo") ""
|
||||
`shouldRespondWith` "any"
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = ["Content-Type" <:> "app/bingo"]
|
||||
, matchHeaders = ["Content-Type" <:> "application/octet-stream"]
|
||||
}
|
||||
|
||||
request methodGet "/rpc/ret_any_mt" (acceptHdrs "text/bango") ""
|
||||
`shouldRespondWith` "any"
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = ["Content-Type" <:> "text/bango"]
|
||||
, matchHeaders = ["Content-Type" <:> "application/octet-stream"]
|
||||
}
|
||||
|
||||
request methodGet "/rpc/ret_any_mt" (acceptHdrs "image/boingo") ""
|
||||
`shouldRespondWith` "any"
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = ["Content-Type" <:> "image/boingo"]
|
||||
, matchHeaders = ["Content-Type" <:> "application/octet-stream"]
|
||||
}
|
||||
|
||||
it "returns custom media type for */* if explicitly set" $ do
|
||||
@@ -276,12 +275,11 @@ spec = describe "custom media types" $ do
|
||||
`shouldRespondWith` 415
|
||||
|
||||
context "on tables" $ do
|
||||
-- TODO not correct, it should return the generic "application/octet-stream"
|
||||
it "returns application/json for */* if not explicitly set" $ do
|
||||
request methodGet "/some_numbers?val=eq.1" (acceptHdrs "*/*") ""
|
||||
`shouldRespondWith` "anything\n1"
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = [matchContentTypeJson]
|
||||
, matchHeaders = ["Content-Type" <:> "application/octet-stream"]
|
||||
}
|
||||
|
||||
it "accepts any media type and sets it as a header" $ do
|
||||
@@ -298,5 +296,5 @@ spec = describe "custom media types" $ do
|
||||
request methodGet "/some_numbers?val=eq.4" (acceptHdrs "unknown/unknown") ""
|
||||
`shouldRespondWith` "anything\n4"
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = ["Content-Type" <:> "unknown/unknown"]
|
||||
, matchHeaders = ["Content-Type" <:> "application/octet-stream"]
|
||||
}
|
||||
|
||||
Vendored
+9
-3
@@ -3663,10 +3663,14 @@ declare
|
||||
resp bytea;
|
||||
begin
|
||||
case req_accept
|
||||
when 'app/chico' then resp := 'chico';
|
||||
when 'app/harpo' then resp := 'harpo';
|
||||
when 'app/chico' then
|
||||
perform set_config('response.headers', json_build_array(json_build_object('Content-Type', req_accept))::text, true);
|
||||
resp := 'chico';
|
||||
when 'app/harpo' then
|
||||
perform set_config('response.headers', json_build_array(json_build_object('Content-Type', req_accept))::text, true);
|
||||
resp := 'harpo';
|
||||
when '*/*' then
|
||||
perform set_config('response.headers', '[{"Content-Type": "app/groucho"}]', true);
|
||||
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';
|
||||
@@ -3689,8 +3693,10 @@ declare
|
||||
begin
|
||||
case req_accept
|
||||
when 'magic/number' then
|
||||
perform set_config('response.headers', json_build_array(json_build_object('Content-Type', req_accept))::text, true);
|
||||
prefix := 'magic';
|
||||
when 'crazy/bingo' then
|
||||
perform set_config('response.headers', json_build_array(json_build_object('Content-Type', req_accept))::text, true);
|
||||
prefix := 'crazy';
|
||||
else
|
||||
prefix := 'anything';
|
||||
|
||||
Reference in New Issue
Block a user