mirror of
https://github.com/labstack/echo.git
synced 2025-04-27 12:32:09 +02:00
Handle GET request with body
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
9016770066
commit
42e83ed0b9
4
bind.go
4
bind.go
@ -30,16 +30,16 @@ type (
|
|||||||
// Bind implements the `Binder#Bind` function.
|
// Bind implements the `Binder#Bind` function.
|
||||||
func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
|
func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
|
||||||
req := c.Request()
|
req := c.Request()
|
||||||
|
if req.ContentLength == 0 {
|
||||||
if req.Method == GET {
|
if req.Method == GET {
|
||||||
if err = b.bindData(i, c.QueryParams(), "query"); err != nil {
|
if err = b.bindData(i, c.QueryParams(), "query"); err != nil {
|
||||||
return NewHTTPError(http.StatusBadRequest, err.Error())
|
return NewHTTPError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctype := req.Header.Get(HeaderContentType)
|
|
||||||
if req.ContentLength == 0 {
|
|
||||||
return NewHTTPError(http.StatusBadRequest, "Request body can't be empty")
|
return NewHTTPError(http.StatusBadRequest, "Request body can't be empty")
|
||||||
}
|
}
|
||||||
|
ctype := req.Header.Get(HeaderContentType)
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(ctype, MIMEApplicationJSON):
|
case strings.HasPrefix(ctype, MIMEApplicationJSON):
|
||||||
if err = json.NewDecoder(req.Body).Decode(i); err != nil {
|
if err = json.NewDecoder(req.Body).Decode(i); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user