-
Notifications
You must be signed in to change notification settings - Fork 19
How to reference HttpRequest body in hooks #207
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
Comments
@restfulhead that's an interesting scenario. Other than your existing workaround, the only other one I'm aware of is for the the hook to read the body and then set the value on the I've considered adding a method |
Yes, it would make my code a little easier and you'd have a recommendation on what to do in this scenario. By the way, I have the same issue regarding the response, too. Usually the response isn't consumed after my hook, but if there were other hooks that also need the response body, then they'd run into the same issue. Unfortunately though copying means we consume the stream and then create it again only for the function (or other hooks) to consume it again. As an alternative, could there be an option to cache the result, so that subsequent calls to Just to mention, I've commented over at undici asking why Also thought about using tee to create two copies of the stream. One copy could be consumed by the caller (i.e. by my hook) and the other stream could replace the original request's stream. But in my scenario I need to prevent further processing of the request if validation fails, so it would just have the same effect of consuming the body multiple times sequentially. |
Yes we can do
https://developer.mozilla.org/en-US/docs/Web/API/Response/clone |
Sounds good |
@ejizba I understand the design choice and looking forward to stream support. However, it would be beneficial to have an option to cache the request body. I'm writing a hook that validates the request body. The hook consumes it using
.json()
. Now the function has no way to access the request body. Because everything is readonly inHttpRequest
I also don't see an easy option to reset/replace the consumed stream. Can you provide guidance how apreInvocation
hook and a function can use the request body?Update: I've tried to use
pipeThrough
, but that still causes thebodyUsed
flag to be true. Looks like the only option is to copy the entire request:Originally posted by @restfulhead in #79 (comment)
The text was updated successfully, but these errors were encountered: