rpc icon indicating copy to clipboard operation
rpc copied to clipboard

[bug] http.Request.Body is not readable in RegisterInterceptFunc or RegisterBeforeFunc

Open groovili opened this issue 5 years ago • 4 comments

Describe the bug

In v2/server package newCodecRequest is called before interceptFunc and beforeFunc and performs request.Body.Close(), in such way funcs which would be called later can't read or alter data in body.

Versions

Go version: go1.14.2 darwin/amd64 package version: 27d3316e212c1acd2a8cb7d0df8a9173d974cbed

Steps to Reproduce

Try to modify request.Body in functions registered with RegisterInterceptFunc or RegisterBeforeFunc.

Expected behavior

Documentation says that functions which added with RegisterInterceptFunc or RegisterBeforeFunc would be called before every request. I assume, that these methods are made to alter or access request content. Since RPC is a protocol which mostly uses request.Body to transfer data, I think it should be accessible and changeable in these functions.

I can make PR to change this behavior if these changes are ok. Also, it wouldn't be breaking changes. Thanks for the package and looking forward to your feedback!

groovili avatar May 01 '20 13:05 groovili

Happy for a PR (with tests) to fix this.

elithrar avatar May 02 '20 15:05 elithrar

Hi @elithrar! Please check the PR above.

groovili avatar May 03 '20 15:05 groovili

@elithrar up

groovili avatar Jul 05 '20 13:07 groovili

up

groovili avatar May 10 '21 12:05 groovili