diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-09-18 13:33:32 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-09-18 13:33:32 +0200 |
commit | c6410076b0a5ed2831868b1b0bf99571cd38c4ab (patch) | |
tree | 4aec2e2019de3062b363c7b10cedc10a4fa67e92 /pkg/api/handlers/compat | |
parent | 273b9545bbf457fb48ff005b4f771b91c3f40681 (diff) | |
download | podman-c6410076b0a5ed2831868b1b0bf99571cd38c4ab.tar.gz podman-c6410076b0a5ed2831868b1b0bf99571cd38c4ab.tar.bz2 podman-c6410076b0a5ed2831868b1b0bf99571cd38c4ab.zip |
stats endpoint: write OK header once
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/api/handlers/compat')
-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() } |