-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose raw body in request #1661
Comments
I was also just looking for a possibility to get the request body in a pre-request function. |
I'm not sure this is a good idea. GUCs are already a bit abused by us and are not really meant to be used that way. Putting potentially huge request bodies with possibly binary data in there, doesn't sound like a good idea. Plus there would need to be an opt-out.
But this is something that I could see happening. What about:
This would have opt-in included. Would something like this solve your use-case, @nathancahill, as well? I can easily see this extended to allow the pre-request function to |
That would be fantastic, much better than adding it to GUCs. |
That would be an optimal solution for my usecase. 👍 |
@wolfgangwalther The So maybe we should use a different function for this case, maybe a |
Yes, that's true. Taking this:
And this, from the other thread:
It looks like we are on the way to some kind of a hook system. If we have pre-body, there are certainly other use-cases that could take a hook as well. If we can have different hooks on different paths, that would be very flexible. We could extend that to pre-request, which could be different by path! All those hooks have in common, that they are optional, so that the regular case is just exactly the same query as without the hooks. Of course So currently we have -- pre-request hook just for the /clients table
CREATE FUNCTION clients_pre_request() RETURNS void
SET pgrst.hook.pre-request='clients'
LANGUAGE SQL AS $$ <big time protection> $$;
-- pre-body hook for clients and projects
CREATE FUNCTION pre_body(body JSON) RETURNS JSON
SET pgrst.hook.pre-body='clients,projects'
LANGUAGE SQL AS $$ <big time transformation> $$; Not sure what kind of values we'd accept in this case for the hook |
I thought a bit more about it... and I don't like it :D. I don't like setting the hooks config on the function definition. The inlining is one thing, but this will easily lead to situations where multiple functions have the same setting. Should we run all of them? In which order? One of them? Which? Complicated! A more natural extension of what we currently have, would be to allow more config options, like this:
I'm not sure about the last one... - we might just not implement this for RPCs, because this could get ugly with finding the right overloaded function - the pre-body fn must not change the name of the arguments, etc... much better would be to allow arbitrary bodies for RPC calls (e.g. via unnamed BYTEA argument, similar to the "single json object" approach). Rules are simple: /clients gets the clients_pre_request_fn, all others the default. So more specific overrides less specific. If both should apply, the clients_pre_request_fn can still make a call to the default. And once we have in-database configuration we can still put a This be a lot less ambiguous, extend the If that's the way to go, we might think about renaming our config options to use dots as separators instead of |
Yes, that last option makes the most sense to me @wolfgangwalther. For RPCs, an unnamed BYTEA argument would be awesome. |
@steve-chavez hello steve! I'm working for a company interested by this feature, is there any way we could sponsor its implementation? |
@FGRibreau Hey Francois. Sure! I've sent you an email to github@fgribreau.com, let's follow up there. |
The unnamed JSON parameter fulfills my use case for this. |
It would be useful to expose the raw body of a request the same way that headers are exposed:
Maybe:
Useful for verifying signed payloads.
I don't have much experience with Haskell but I believe it would fit in here: https://github.com/PostgREST/postgrest/blob/master/src/PostgREST/Middleware.hs#L46
The text was updated successfully, but these errors were encountered: