From 0af8be35bb9d29e29f2a3af3acf9a65fd41ef7df Mon Sep 17 00:00:00 2001 From: mirwaisx <57108408+mirwaisx@users.noreply.github.com> Date: Fri, 15 Nov 2019 14:03:45 +0100 Subject: [PATCH] -bugfix #889 set body corretly in case of missing content-type (#950) --- api/handler/api/util.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/api/handler/api/util.go b/api/handler/api/util.go index 7a4607c7..824ec5da 100644 --- a/api/handler/api/util.go +++ b/api/handler/api/util.go @@ -29,16 +29,20 @@ func requestToProto(r *http.Request) (*api.Request, error) { ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) if err != nil { - ct = "application/x-www-form-urlencoded" + ct = "text/plain; charset=UTF-8" //default CT is text/plain r.Header.Set("Content-Type", ct) } - switch ct { - case "application/x-www-form-urlencoded": - // expect form vals - default: - data, _ := ioutil.ReadAll(r.Body) - req.Body = string(data) + //set the body: + if r.Body != nil { + switch ct { + case "application/x-www-form-urlencoded": + // expect form vals in Post data + default: + + data, _ := ioutil.ReadAll(r.Body) + req.Body = string(data) + } } // Set X-Forwarded-For if it does not exist