Skip to content

Commit b129098

Browse files
cousinbensonvishr
authored andcommitted
dont return 400 for empty bodies (labstack#1410)
* dont return 400 for empty bodies * remove test for missing contentlength 0
1 parent 81a6608 commit b129098

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

bind.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,11 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
4343
if err := b.bindData(i, params, "param"); err != nil {
4444
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
4545
}
46-
46+
if err = b.bindData(i, c.QueryParams(), "query"); err != nil {
47+
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
48+
}
4749
if req.ContentLength == 0 {
48-
if req.Method == http.MethodGet || req.Method == http.MethodDelete {
49-
if err = b.bindData(i, c.QueryParams(), "query"); err != nil {
50-
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
51-
}
52-
return
53-
}
54-
return NewHTTPError(http.StatusBadRequest, "Request body can't be empty")
50+
return
5551
}
5652
ctype := req.Header.Get(HeaderContentType)
5753
switch {

bind_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ func TestBindForm(t *testing.T) {
147147
assert := assert.New(t)
148148

149149
testBindOkay(assert, strings.NewReader(userForm), MIMEApplicationForm)
150-
testBindError(assert, nil, MIMEApplicationForm, nil)
151150
e := New()
152151
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userForm))
153152
rec := httptest.NewRecorder()

0 commit comments

Comments
 (0)