Addressing certain comments from last review

This commit is contained in:
Denis Makogon
2017-10-07 01:20:53 +03:00
parent 11e5c80b4f
commit b4b5302a44

View File

@@ -36,8 +36,9 @@ func (h *JSONProtocol) DumpJSON(w io.Writer, req *http.Request) error {
// this shouldn't happen // this shouldn't happen
return err return err
} }
if req.Body != nil {
_, err := io.WriteString(h.in, `"body":"`) if req.ContentLength != 0 {
_, err := io.WriteString(h.in, `"body": `)
if err != nil { if err != nil {
// this shouldn't happen // this shouldn't happen
return err return err
@@ -52,13 +53,12 @@ func (h *JSONProtocol) DumpJSON(w io.Writer, req *http.Request) error {
if err != nil { if err != nil {
return err return err
} }
_, err = io.WriteString(h.in, `",`) _, err = io.WriteString(h.in, `,`)
if err != nil { if err != nil {
// this shouldn't happen // this shouldn't happen
return err return err
} }
defer bb.Reset() defer bb.Reset()
defer req.Body.Close()
} }
_, err = io.WriteString(h.in, `"headers:"`) _, err = io.WriteString(h.in, `"headers:"`)
if err != nil { if err != nil {
@@ -99,7 +99,7 @@ func (h *JSONProtocol) Dispatch(w io.Writer, req *http.Request) error {
} }
} }
rw.WriteHeader(jout.StatusCode) rw.WriteHeader(jout.StatusCode)
_, err = rw.Write([]byte(jout.Body)) // TODO timeout _, err = io.WriteString(rw, jout.Body) // TODO timeout
if err != nil { if err != nil {
return err return err
} }