From 12b0ebff7dbd32497916c669fa1f90e40baa28d4 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Wed, 22 Oct 2014 17:48:50 -0700 Subject: [PATCH] server/http: Use Response as Reader instead of manually getting output data --- server/http/http.go | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/server/http/http.go b/server/http/http.go index 9fdfacf8b..dbf8b473b 100644 --- a/server/http/http.go +++ b/server/http/http.go @@ -112,27 +112,10 @@ func (i *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } - val := res.Value() - - // if the output value is a io.Reader, stream its output in the request body - if stream, ok := val.(io.Reader); ok { - io.Copy(w, stream) - return - } - - // otherwise, marshall and output the response value or error - if val != nil || res.Error() != nil { - output, err := res.Marshal() - - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - fmt.Println(err) - return - } - - if output != nil { - w.Write(output) - } + _, err = io.Copy(w, res) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) } }