-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make request body readable and changeable in interceptFunc and before…
…Func (#81) Hi! This PR gives users the ability to access and change `request.Body` in functions registered with `RegisterInterceptFunc` and `RegisterBeforeFunc`. 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:** 1. In **rpc/v2** close `request.Body` after the execution of `beforeFunc`'s and `interceptFunc`'s. Update codec request info after calls to functions above. 2. Read request body bytes, decode it to codec format and provide `bytes.Buffer` and `request.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` and `RegisterBeforeFunc` 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!
- Loading branch information
Showing
5 changed files
with
190 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters