return ErrBodylessRequest on get method etc.

This commit is contained in:
kevin
2020-08-12 14:31:11 +08:00
parent 80d55dbc02
commit 88a73f1042
3 changed files with 30 additions and 1 deletions

View File

@@ -83,8 +83,13 @@ func ParseHeader(headerValue string) map[string]string {
// Parses the post request which contains json in body.
func ParseJsonBody(r *http.Request, v interface{}) error {
var reader io.Reader
switch r.Method {
case http.MethodDelete, http.MethodPatch, http.MethodPost, http.MethodPut:
default:
return ErrBodylessRequest
}
var reader io.Reader
if withJsonBody(r) {
reader = io.LimitReader(r.Body, maxBodyLen)
} else {