From a26fc2b672d9df0b32c9763a84019f213377e114 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 12 Aug 2020 14:37:34 +0800 Subject: [PATCH] parse body only if content length > 0 --- rest/httpx/requests.go | 6 +++++- rest/httpx/vars.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rest/httpx/requests.go b/rest/httpx/requests.go index e5c4be4a..7f8d52cc 100644 --- a/rest/httpx/requests.go +++ b/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. diff --git a/rest/httpx/vars.go b/rest/httpx/vars.go index f4a6d6d9..001d2d6d 100644 --- a/rest/httpx/vars.go +++ b/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")