-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Cannot read request body after ctx.Bind #2681
Comments
Yep, there needs to be |
By reassigning ReaderCloser to Body in |
In Go, the request body is represented as an io.ReadCloser, which is a stream that can only be read once. Once it’s consumed (e.g., by ctx.Bind()), the body is no longer available for reading. This is a fundamental aspect of streams in Go. |
Issue Description
I want to get the request body in httpErrorHandler, but I can't.
Once a request body is read by
ctx.Bind
, it cannot be read afterward.To read again after reading, the ReaderCloser must be set, but
DefaultBinder#BindBody
does not do this.echo/middleware/body_dump.go
Line 72 in 7544796
What is the best way to do this?
Checklist
Expected behavior
Can read the request body after
ctx.Bind
or inhttpErrorHandler
Actual behavior
Cannot read the request body after
ctx.Bind
Steps to reproduce
Working code to debug
When a POST request is sent with
{"aaa": "hoge"}
, the following log is outputVersion/commit
v4.12.0
The text was updated successfully, but these errors were encountered: