diff options
Diffstat (limited to 'pkg/api')
-rw-r--r-- | pkg/api/handlers/compat/containers_stats.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/pkg/api/handlers/compat/containers_stats.go b/pkg/api/handlers/compat/containers_stats.go index 3d7d49ad3..d7970741d 100644 --- a/pkg/api/handlers/compat/containers_stats.go +++ b/pkg/api/handlers/compat/containers_stats.go @@ -75,6 +75,17 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) { } } + // Write header and content type. + w.WriteHeader(http.StatusOK) + w.Header().Add("Content-Type", "application/json") + if flusher, ok := w.(http.Flusher); ok { + flusher.Flush() + } + + // Setup JSON encoder for streaming. + coder := json.NewEncoder(w) + coder.SetEscapeHTML(true) + for ok := true; ok; ok = query.Stream { // Container stats stats, err := ctnr.GetContainerStats(stats) @@ -175,7 +186,10 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) { Networks: net, } - utils.WriteJSON(w, http.StatusOK, s) + if err := coder.Encode(s); err != nil { + utils.InternalServerError(w, err) + return + } if flusher, ok := w.(http.Flusher); ok { flusher.Flush() } |