Skip to content

Commit

Permalink
dont return 400 for empty bodies (#1410)
Browse files Browse the repository at this point in the history
* dont return 400 for empty bodies

* remove test for missing contentlength 0
  • Loading branch information
cousinbenson authored and vishr committed Sep 30, 2019
1 parent 81a6608 commit b129098
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
12 changes: 4 additions & 8 deletions bind.go
Expand Up @@ -43,15 +43,11 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
if err := b.bindData(i, params, "param"); err != nil {
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
}

if err = b.bindData(i, c.QueryParams(), "query"); err != nil {
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
}
if req.ContentLength == 0 {
if req.Method == http.MethodGet || req.Method == http.MethodDelete {
if err = b.bindData(i, c.QueryParams(), "query"); err != nil {
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
}
return
}
return NewHTTPError(http.StatusBadRequest, "Request body can't be empty")
return
}
ctype := req.Header.Get(HeaderContentType)
switch {
Expand Down
1 change: 0 additions & 1 deletion bind_test.go
Expand Up @@ -147,7 +147,6 @@ func TestBindForm(t *testing.T) {
assert := assert.New(t)

testBindOkay(assert, strings.NewReader(userForm), MIMEApplicationForm)
testBindError(assert, nil, MIMEApplicationForm, nil)
e := New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userForm))
rec := httptest.NewRecorder()
Expand Down

0 comments on commit b129098

Please sign in to comment.