mirror of
https://github.com/labstack/echo.git
synced 2025-07-17 01:43:02 +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:
12
bind.go
12
bind.go
@ -43,15 +43,11 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
|
|||||||
if err := b.bindData(i, params, "param"); err != nil {
|
if err := b.bindData(i, params, "param"); err != nil {
|
||||||
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
|
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.ContentLength == 0 {
|
||||||
if req.Method == http.MethodGet || req.Method == http.MethodDelete {
|
return
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
ctype := req.Header.Get(HeaderContentType)
|
ctype := req.Header.Get(HeaderContentType)
|
||||||
switch {
|
switch {
|
||||||
|
@ -147,7 +147,6 @@ func TestBindForm(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testBindOkay(assert, strings.NewReader(userForm), MIMEApplicationForm)
|
testBindOkay(assert, strings.NewReader(userForm), MIMEApplicationForm)
|
||||||
testBindError(assert, nil, MIMEApplicationForm, nil)
|
|
||||||
e := New()
|
e := New()
|
||||||
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userForm))
|
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userForm))
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
|
Reference in New Issue
Block a user