1
0
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:
Vishal Rana
2025-09-15 18:47:57 -07:00
parent 61da50fefc
commit 2fb84197e9
2 changed files with 25 additions and 0 deletions

View File

@@ -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",