Closed
Description
Issue Description
The default binder currently returns 400 if req.ContentLength == 0
during methods that aren't GET or DELETE. It is generally NOT regarded bad practice to make POST / PUT requests with an empty body. It should be up the resource to determine whether or not this should error and not the HTTP protocol.
#1214 was created with regards to this issue, but eventually went stale after no action was taken.
Some discussion on the topic can be found here:
- https://stackoverflow.com/questions/4191593/is-it-considered-bad-practice-to-perform-http-post-without-entity-body
- http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0272.html
Checklist
- Dependencies installed
- No typos
- Searched existing issues and docs
Expected behaviour
c.Bind() should not return 400 for POST / PUT with empty bodies
Actual behaviour
c.Bind() returns 400 for POST / PUT with empty bodies
Steps to reproduce
call c.Bind() in a POST handler with an empty body
Working code to debug
package main
import (
"net/http"
"github.com/labstack/echo"
)
func main() {
srv := echo.New()
srv.POST("/test", testPostBody)
srv.Start(":1234")
}
type Params struct {
Foo string `param:"foo"`
Bar string `query:"bar"`
}
func testPostBody(c echo.Context) error {
var params Params
if err := c.Bind(¶ms); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
return c.String(200, "OK")
}
Version/commit
Metadata
Metadata
Assignees
Labels
No labels