add: add "Vary" header to responses

Co-authored-by: Steve Chavez <stevechavezast@gmail.com>
This commit is contained in:
Andrei Dziahel
2026-03-16 09:55:20 -05:00
committed by Steve Chavez
co-authored by Steve Chavez
parent d5df12c9c2
commit 1f54e2accc
8 changed files with 86 additions and 10 deletions
@@ -196,6 +196,23 @@
pdSchema: public
pdVolatility: Volatile
- - qiName: custom_vary_hdr
qiSchema: public
- - pdDescription: null
pdFuncSettings: []
pdHasVariadic: false
pdName: custom_vary_hdr
pdParams: []
pdReturnType:
contents:
contents:
qiName: void
qiSchema: pg_catalog
tag: Scalar
tag: Single
pdSchema: public
pdVolatility: Volatile
- - qiName: get_postgres_version
qiSchema: public
- - pdDescription: null
+7
View File
@@ -258,3 +258,10 @@ $_$ language sql;
create or replace function notify_pgrst() returns void as $$
notify pgrst;
$$ language sql;
create or replace function custom_vary_hdr() returns void as $$
begin
perform set_config('response.headers', '[{"Vary": "X-Test-Accept"}]', false);
end
$$ language plpgsql;
+20
View File
@@ -1811,3 +1811,23 @@ def test_client_error_verbosity_config(defaultenv):
"details": None,
"hint": "Perhaps you meant the table 'public.items'",
}
def test_vary_custom_header_set(defaultenv):
"Test default Vary header value is overridden in pre-request database function"
env = {**defaultenv, "PGRST_DB_PRE_REQUEST": "custom_vary_hdr"}
with run(env=env) as postgrest:
response = postgrest.session.get("/projects")
assert response.headers["Vary"] == "X-Test-Accept"
def test_vary_default_header_set(defaultenv):
"Test default Vary header value matches default one"
with run(env=defaultenv) as postgrest:
response = postgrest.session.get("/projects")
assert response.headers["Vary"] == "Accept, Prefer, Range"