diff options
Diffstat (limited to 'pkg/api/handlers/utils/handler.go')
-rw-r--r-- | pkg/api/handlers/utils/handler.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/pkg/api/handlers/utils/handler.go b/pkg/api/handlers/utils/handler.go index 0815e6eca..65698bfd3 100644 --- a/pkg/api/handlers/utils/handler.go +++ b/pkg/api/handlers/utils/handler.go @@ -12,19 +12,19 @@ import ( // WriteResponse encodes the given value as JSON or string and renders it for http client func WriteResponse(w http.ResponseWriter, code int, value interface{}) { - switch value.(type) { + switch v := value.(type) { case string: w.Header().Set("Content-Type", "text/plain; charset=us-ascii") w.WriteHeader(code) - if _, err := fmt.Fprintln(w, value); err != nil { + if _, err := fmt.Fprintln(w, v); err != nil { log.Errorf("unable to send string response: %q", err) } case *os.File: w.Header().Set("Content-Type", "application/octet; charset=us-ascii") w.WriteHeader(code) - if _, err := io.Copy(w, value.(*os.File)); err != nil { + if _, err := io.Copy(w, v); err != nil { log.Errorf("unable to copy to response: %q", err) } default: @@ -33,6 +33,7 @@ func WriteResponse(w http.ResponseWriter, code int, value interface{}) { } func WriteJSON(w http.ResponseWriter, code int, value interface{}) { + // FIXME: we don't need to write the header in all/some circumstances. w.Header().Set("Content-Type", "application/json") w.WriteHeader(code) |