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:
parent
81a66086ae
commit
b129098169
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 {
|
||||
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 {
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user