From 1f589d641ee0b825093a8f8dbaedb97a444c2c2b Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Sat, 30 Sep 2017 22:50:02 +0300 Subject: [PATCH] Let function write headers to a response --- api/agent/protocol/json.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/agent/protocol/json.go b/api/agent/protocol/json.go index fb137f344..b1465cf56 100644 --- a/api/agent/protocol/json.go +++ b/api/agent/protocol/json.go @@ -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 {