Add ability to map GUC to http response headers
This commit is contained in:
committed by
Steve Chávez
parent
38de56de4a
commit
b9a591aecb
@@ -286,6 +286,41 @@ spec =
|
||||
it "defaults to status 500 if RAISE code is PT not followed by a number" $
|
||||
get "/rpc/raise_bad_pt" `shouldRespondWith` 500
|
||||
|
||||
context "GUC headers" $ do
|
||||
it "succeeds setting the headers" $ do
|
||||
get "/rpc/get_projects_and_guc_headers?id=eq.2&select=id"
|
||||
`shouldRespondWith` [json|[{"id": 2}]|]
|
||||
{matchHeaders = [
|
||||
matchContentTypeJson,
|
||||
"X-Test" <:> "key1=val1; someValue; key2=val2",
|
||||
"X-Test-2" <:> "key1=val1"]}
|
||||
get "/rpc/get_int_and_guc_headers?num=1"
|
||||
`shouldRespondWith` [json|1|]
|
||||
{matchHeaders = [
|
||||
matchContentTypeJson,
|
||||
"X-Test" <:> "key1=val1; someValue; key2=val2",
|
||||
"X-Test-2" <:> "key1=val1"]}
|
||||
post "/rpc/get_int_and_guc_headers" [json|{"num": 1}|]
|
||||
`shouldRespondWith` [json|1|]
|
||||
{matchHeaders = [
|
||||
matchContentTypeJson,
|
||||
"X-Test" <:> "key1=val1; someValue; key2=val2",
|
||||
"X-Test-2" <:> "key1=val1"]}
|
||||
|
||||
it "fails when setting headers with wrong json structure" $ do
|
||||
get "/rpc/bad_guc_headers_1" `shouldRespondWith` 500
|
||||
get "/rpc/bad_guc_headers_2" `shouldRespondWith` 500
|
||||
get "/rpc/bad_guc_headers_3" `shouldRespondWith` 500
|
||||
post "/rpc/bad_guc_headers_1" [json|{}|] `shouldRespondWith` 500
|
||||
|
||||
it "can set the same http header twice" $
|
||||
get "/rpc/set_cookie_twice"
|
||||
`shouldRespondWith` "null"
|
||||
{matchHeaders = [
|
||||
matchContentTypeJson,
|
||||
"Set-Cookie" <:> "sessionid=38afes7a8; HttpOnly; Path=/",
|
||||
"Set-Cookie" <:> "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly"]}
|
||||
|
||||
context "only for POST rpc" $ do
|
||||
context "expects a single json object" $ do
|
||||
it "does not expand posted json into parameters" $
|
||||
|
||||
Vendored
+26
@@ -1306,6 +1306,32 @@ begin
|
||||
raise sqlstate 'PT40A' using message = 'Wrong';
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
create or replace function test.get_projects_and_guc_headers() returns setof test.projects as $$
|
||||
set local "response.headers" = '[{"X-Test": "key1=val1; someValue; key2=val2"}, {"X-Test-2": "key1=val1"}]';
|
||||
select * from test.projects;
|
||||
$$ language sql;
|
||||
|
||||
create or replace function test.get_int_and_guc_headers(num int) returns integer as $$
|
||||
set local "response.headers" = '[{"X-Test":"key1=val1; someValue; key2=val2"},{"X-Test-2":"key1=val1"}]';
|
||||
select num;
|
||||
$$ language sql;
|
||||
|
||||
create or replace function test.bad_guc_headers_1() returns void as $$
|
||||
set local "response.headers" = '{"X-Test": "invalid structure for headers"}';
|
||||
$$ language sql;
|
||||
|
||||
create or replace function test.bad_guc_headers_2() returns void as $$
|
||||
set local "response.headers" = '["invalid", "structure", "for", "headers"]';
|
||||
$$ language sql;
|
||||
|
||||
create or replace function test.bad_guc_headers_3() returns void as $$
|
||||
set local "response.headers" = '{"X-Test": "invalid", "X-Test-2": "structure", "X-Test-3": "for headers"}';
|
||||
$$ language sql;
|
||||
|
||||
create or replace function test.set_cookie_twice() returns void as $$
|
||||
set local "response.headers" = '[{"Set-Cookie": "sessionid=38afes7a8; HttpOnly; Path=/"}, {"Set-Cookie": "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly"}]';
|
||||
$$ language sql;
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user