Postgrest: Access HTTP headers inside PSQL

Created on 10 Feb 2017  路  7Comments  路  Source: PostgREST/postgrest

Like in Oracle PL/SQL via UTL_HTTP.GET_HEADER, Is it possible to pass all header information to access them via psql function, smth like :

current_settings("http_host");
current_settings("http_referer");

enhancement

Most helpful comment

I thought there was a github issue about this already, but I can't find it...

Anyway, this is a good idea. We could prefix the name of the variables like request.header.http_referer so that it is similar to how we store JWT claims (e.g. request.jwt.claim.email). One thing is we'll want to avoid making an extra roundtrip to the database to set the variables if we can help it, but it's probably doable.

All 7 comments

I thought there was a github issue about this already, but I can't find it...

Anyway, this is a good idea. We could prefix the name of the variables like request.header.http_referer so that it is similar to how we store JWT claims (e.g. request.jwt.claim.email). One thing is we'll want to avoid making an extra roundtrip to the database to set the variables if we can help it, but it's probably doable.

@begriffs I think you were searching after https://github.com/begriffs/postgrest/pull/664

We could also set IP address of current request. It can be useful to save IPs in the database, for example when you insert a comment on a forum.

@ruslantalpa fyi

@eldadj see #849
until it's merged, you can use the patch.

Looks like it's implemented and released in 0.4.1, should we close the ticket?
@tjunussov maybe you would like to verify?

Closing. Can re-open if anybody runs into a problem with it.

For those (like me) who wonder how to use it, this one works:

current_setting('request.header.user-agent', true)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

isairz picture isairz  路  24Comments

ric2b picture ric2b  路  21Comments

tomberek picture tomberek  路  19Comments

nicklasaven picture nicklasaven  路  22Comments

dudleycarr picture dudleycarr  路  25Comments