1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

dont return 400 for empty bodies (#1410)

* dont return 400 for empty bodies

* remove test for missing contentlength 0
This commit is contained in:
Bob Hall 2019-09-30 18:56:32 +01:00 committed by Vishal Rana
parent 81a66086ae
commit b129098169
2 changed files with 4 additions and 9 deletions

12
bind.go
View File

@ -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 {

View File

@ -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()