mirror of
https://github.com/containers/podman.git
synced 2025-08-24 10:04:57 +08:00
stats endpoint: write OK header once
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user