Revert the DefaultBinder empty body handling changes following
@aldas's concerns about:
- Body replacement potentially interfering with custom readers
- Lack of proper reproduction case for the original issue
- Potential over-engineering for an edge case
The "read one byte and reconstruct body" approach could interfere
with users who add custom readers with specific behavior.
Waiting for better reproduction case and less invasive solution.
Refs: https://github.com/labstack/echo/issues/2813#issuecomment-3294563361🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Fix issue where POST requests with empty bodies and ContentLength=-1
(unknown/chunked encoding) incorrectly fail with 415 Unsupported Media Type.
The DefaultBinder.BindBody method now properly detects truly empty bodies
when ContentLength=-1 by peeking at the first byte. If no content is found,
it returns early without error. If content exists, it reconstructs the body
to preserve the original data.
Fixes#2813🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Use Go 1.25 in CI
* Disable test: in Go 1.24 and earlier http.NoBody would result ContentLength=-1 but as of Go 1.25 http.NoBody would result ContentLength=0 I am too lazy to bother documenting this as 2 version specific tests.
Currently, echo supports binding data from query, path or body.
Sometimes we need to read bind data from headers. It would be nice to
automatically bind those using the `bindData` func, which is already
well prepared to accept `http.Header`.
I didn't add this to the `Bind` func, so this will not happen
automatically. Main reason is backwards compatability. It might be
confusing if variables are bound from headers when upgrading, and might
even have become a security issue as pointed out in #1670.
* Add docs for BindHeaders
* Add test for BindHeader with invalid data type
* Binding query/path params and form fields to struct only works for fields that have explicit TAG defined on struct
* remove unnecessary benchmark after change because it is not valid test anymore
* Added feature to map url params to a struct with the default binder
* Added test for mix of POST data and bound params
* Renamed variables
* Added error check
* Removed unneded fix
Unmarshalling body params with json.Unmarshal supports case-insensitive
matching against struct tags. Matching query params case insensitive
provides a more sane and consistent experience for API consumers.
The original url.Values keys remain case sensitive.
Old error message
`
Unmarshal type error: expected=int, got=string, offset=47
`
New error message
`
Unmarshal type error: expected=int, got=string, field=age, offset=47
`
Make it easy to fix for client.