Read request body and see if it's not empty then decide whether write it or not

This commit is contained in:
Denis Makogon
2017-10-07 01:24:43 +03:00
parent b4b5302a44
commit 9f3bfa1005

View File

@@ -37,19 +37,19 @@ func (h *JSONProtocol) DumpJSON(w io.Writer, req *http.Request) error {
return err
}
if req.ContentLength != 0 {
_, err := io.WriteString(h.in, `"body": `)
if err != nil {
// this shouldn't happen
return err
}
bb := new(bytes.Buffer)
_, err = bb.ReadFrom(req.Body)
if err != nil {
return err
}
err = stdin.Encode(bb.String())
reqData := bb.String()
if reqData != "" {
_, err := io.WriteString(h.in, `"body": `)
if err != nil {
// this shouldn't happen
return err
}
err = stdin.Encode(reqData)
if err != nil {
return err
}