mirror of
https://github.com/labstack/echo.git
synced 2025-12-03 22:59:09 +02:00
Fix DefaultBinder empty body handling for unknown ContentLength
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>
This commit is contained in:
@@ -1082,6 +1082,14 @@ func TestDefaultBinder_BindBody(t *testing.T) {
|
||||
givenContent: strings.NewReader(""),
|
||||
expect: &Node{ID: 0, Node: ""},
|
||||
},
|
||||
{
|
||||
name: "ok, POST with empty body and ContentLength -1 (Issue #2813)",
|
||||
givenURL: "/api/real_node/endpoint?node=xxx",
|
||||
givenMethod: http.MethodPost,
|
||||
givenContent: strings.NewReader(""),
|
||||
whenChunkedBody: true, // This sets ContentLength to -1
|
||||
expect: &Node{ID: 0, Node: ""},
|
||||
},
|
||||
{
|
||||
name: "ok, JSON POST bind to struct with: path + query + chunked body",
|
||||
givenURL: "/api/real_node/endpoint?node=xxx",
|
||||
|
||||
Reference in New Issue
Block a user