Skip to content

Commit 7b331ee

Browse files
committed
Revert the ContentLength conditions for BindBody
1 parent 14464bf commit 7b331ee

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

bind.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,7 @@ func (b *DefaultBinder) BindQueryParams(c Context, i interface{}) error {
6767
// See MIMEMultipartForm: https://golang.org/pkg/net/http/#Request.ParseMultipartForm
6868
func (b *DefaultBinder) BindBody(c Context, i interface{}) (err error) {
6969
req := c.Request()
70-
var isChunked bool
71-
for _, enc := range req.TransferEncoding {
72-
if enc == "chunked" {
73-
isChunked = true
74-
break
75-
}
76-
}
77-
if req.ContentLength <= 0 && !isChunked {
70+
if req.ContentLength == 0 {
7871
return
7972
}
8073

bind_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,21 @@ func TestDefaultBinder_BindBody(t *testing.T) {
10631063
expectError: "code=415, message=Unsupported Media Type",
10641064
},
10651065
{
1066-
name: "ok, JSON POST bind to struct with: path + query + http.NoBody",
1066+
name: "nok, JSON POST with http.NoBody",
10671067
givenURL: "/api/real_node/endpoint?node=xxx",
10681068
givenMethod: http.MethodPost,
10691069
givenContentType: MIMEApplicationJSON,
10701070
givenContent: http.NoBody,
10711071
expect: &Node{ID: 0, Node: ""},
1072+
expectError: "code=400, message=EOF, internal=EOF",
1073+
},
1074+
{
1075+
name: "ok, JSON POST with empty body",
1076+
givenURL: "/api/real_node/endpoint?node=xxx",
1077+
givenMethod: http.MethodPost,
1078+
givenContentType: MIMEApplicationJSON,
1079+
givenContent: strings.NewReader(""),
1080+
expect: &Node{ID: 0, Node: ""},
10721081
},
10731082
{
10741083
name: "ok, JSON POST bind to struct with: path + query + chunked body",

0 commit comments

Comments
 (0)