Make request body readable and changeable in interceptFunc and beforeFunc #81
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
This PR gives users the ability to access and change
request.Body
in functions registered withRegisterInterceptFunc
andRegisterBeforeFunc
. I've already described it in issue #80.Also, I've added couple of simple tests to check ability to change request data in these functions.
Changes:
request.Body
after the execution ofbeforeFunc
's andinterceptFunc
's. Update codec request info after calls to functions above.bytes.Buffer
andrequest.Body
for underlying functions in v2/json, v2/json2 and v2/protorpc codecs.Of course, exists a better way to do that, but it will require changes in the signature of
RegisterInterceptFunc
andRegisterBeforeFunc
and it would be breaking changes. If both of these methods will have an original*http.Request
as input parameter, they could be executed before the creation of codec. In this case, users can access and alter request data, and only after that it would be read by the codec and marshaled to service request params. But since these changes are breaking, it's not an option at the moment, probably it can fit the next version or release.Would be nice to know your opinion, thanks!