Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (b *DefaultBinder) BindQueryParams(c Context, i interface{}) error {
// See MIMEMultipartForm: https://golang.org/pkg/net/http/#Request.ParseMultipartForm
func (b *DefaultBinder) BindBody(c Context, i interface{}) (err error) {
req := c.Request()
if req.ContentLength == 0 {
if req.ContentLength <= 0 {
return
}

Expand Down
8 changes: 8 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,14 @@ func TestDefaultBinder_BindBody(t *testing.T) {
expect: &Node{ID: 0, Node: ""},
expectError: "code=415, message=Unsupported Media Type",
},
{
name: "ok, JSON POST bind to struct with: path + query + http.NoBody",
givenURL: "/api/real_node/endpoint?node=xxx",
givenMethod: http.MethodPost,
givenContentType: MIMEApplicationJSON,
givenContent: http.NoBody,
expect: &Node{ID: 0, Node: ""},
},
}

for _, tc := range testCases {
Expand Down
Loading