-
-
Notifications
You must be signed in to change notification settings - Fork 956
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
Update body
after beforeRequest
#1453
Conversation
@szmarczak @sindresorhus Any feedback on this? |
@Giotino Don't forget to mark the PR as "Ready for review" when you're done with all changes from your side. |
Does this need any docs changes or additions? If the capability is not already documented, we should do so. |
Of course, but this PR is not yet ready for review. The things that I want to discuss are:
|
I strongly disagree. When I rewrote Got, I meant this to be used only internally. Why anyone would want to access the computed body anyway? |
I agree on this but this would require re-normalization, which wouldn't be efficient. Not sure if the code would look good though. I've been thinking of another way to normalize options, I'll let you know when I have a draft of it. Can't we [for now] just mention that overriding |
I think we can go with this, also changing the Today (or tomorrow) I'm going to add the documentation and then it should be ready for review. |
Regarding the computed body thing, why do you need it? I can't think of any example, just asking :) |
I have no real life example, but if someone want to apply some modification before the request that depends on the body, or maybe they want only to do something with the computed body (maybe log it). I'm not saying that it's a "must have" but I'm exploring some possibilities, currently I don't think anyone is using it as that, but never say never. Maybe we could implement the feature like it's now on the PR write body (only |
This PR makes possibile updating the body in a
beforeRquest
hookExample:
This provides a "low level" access to the body, as can be seen in the example there's still the need to manually update headers and other properties affected by the body.
Actually there's no way to access the final body computed by Got, meaning that a user can't find anywhere in the
options
parameter the body generated by_finalizeBody()
. This could give us a chance to implementbreforeRequest
hook as follow:where
computedValues
contains computed values (who would have guessed... :) ) from Got such as the finalbody
.At this point the user should edit the
computedValues
insted of theoptions
in order to alter the request behavior.Checklist
Fixes #1408
Fixes #1427