Let function write headers to a response

This commit is contained in:
Denis Makogon
2017-09-30 22:50:02 +03:00
parent caf1488dd9
commit 1f589d641e

View File

@@ -71,7 +71,7 @@ func (h *JSONProtocol) Dispatch(w io.Writer, req *http.Request) error {
err := h.DumpJSON(w, req)
if err != nil {
return respondWithError(
w, fmt.Errorf("error reader JSON object from request body: %s", err.Error()))
w, fmt.Errorf("unable to write JSON into STDIN: %s", err.Error()))
}
jout := new(JSONIO)
dec := json.NewDecoder(h.out)
@@ -83,6 +83,12 @@ func (h *JSONProtocol) Dispatch(w io.Writer, req *http.Request) error {
// this has to be done for pulling out:
// - status code
// - body
// - headers
for k, vs := range jout.Headers {
for _, v := range vs {
rw.Header().Add(k, v) // on top of any specified on the route
}
}
rw.WriteHeader(jout.StatusCode)
_, err = rw.Write([]byte(jout.Body)) // TODO timeout
if err != nil {