Răsfoiți Sursa

parse body only if content length > 0

kevin 4 ani în urmă
părinte
comite
96b6d2ab58
2 a modificat fișierele cu 6 adăugiri și 2 ștergeri
  1. 5 1
      rest/httpx/requests.go
  2. 1 1
      rest/httpx/vars.go

+ 5 - 1
rest/httpx/requests.go

@@ -34,7 +34,11 @@ func Parse(r *http.Request, v interface{}) error {
 		return err
 	}
 
-	return ParseJsonBody(r, v)
+	if r.ContentLength > 0 {
+		return ParseJsonBody(r, v)
+	}
+
+	return nil
 }
 
 // Parses the form request.

+ 1 - 1
rest/httpx/vars.go

@@ -20,4 +20,4 @@ const (
 	CodeSignatureInvalidToken
 )
 
-var ErrBodylessRequest = errors.New("not a POST|PUT|PATCH request")
+var ErrBodylessRequest = errors.New("not a POST|PUT|PATCH|DELETE request")