-bugfix #889 set body corretly in case of missing content-type (#950)

This commit is contained in:
mirwaisx 2019-11-15 14:03:45 +01:00 committed by Asim Aslam
parent a91b3f3e8b
commit 0af8be35bb

View File

@ -29,17 +29,21 @@ func requestToProto(r *http.Request) (*api.Request, error) {
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil { 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) r.Header.Set("Content-Type", ct)
} }
//set the body:
if r.Body != nil {
switch ct { switch ct {
case "application/x-www-form-urlencoded": case "application/x-www-form-urlencoded":
// expect form vals // expect form vals in Post data
default: default:
data, _ := ioutil.ReadAll(r.Body) data, _ := ioutil.ReadAll(r.Body)
req.Body = string(data) req.Body = string(data)
} }
}
// Set X-Forwarded-For if it does not exist // Set X-Forwarded-For if it does not exist
if ip, _, err := net.SplitHostPort(r.RemoteAddr); err == nil { if ip, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {