From 8566ef71c0a0bcc609d74b7d3311b24f0724eab3 Mon Sep 17 00:00:00 2001 From: Anders Hausding Date: Mon, 25 Aug 2025 13:29:48 +0200 Subject: [PATCH] fix: set header fields before response status code to prevent missing fields Signed-off-by: Anders Hausding --- pkg/api/handlers/compat/images_push.go | 2 +- pkg/api/handlers/libpod/containers_stats.go | 2 +- pkg/api/handlers/libpod/images.go | 2 +- pkg/api/handlers/libpod/images_pull.go | 2 +- pkg/api/handlers/libpod/images_push.go | 2 +- pkg/api/handlers/libpod/manifests.go | 2 +- pkg/api/handlers/utils/images.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/api/handlers/compat/images_push.go b/pkg/api/handlers/compat/images_push.go index ff6d64e7b2..b7ff0dd5c4 100644 --- a/pkg/api/handlers/compat/images_push.go +++ b/pkg/api/handlers/compat/images_push.go @@ -120,8 +120,8 @@ func PushImage(w http.ResponseWriter, r *http.Request) { statusWritten := false writeStatusCode := func(code int) { if !statusWritten { - w.WriteHeader(code) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(code) flush() statusWritten = true } diff --git a/pkg/api/handlers/libpod/containers_stats.go b/pkg/api/handlers/libpod/containers_stats.go index 7dc4dd6754..3d93b531f2 100644 --- a/pkg/api/handlers/libpod/containers_stats.go +++ b/pkg/api/handlers/libpod/containers_stats.go @@ -76,8 +76,8 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) { return } // Write header and content type. - w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) wroteContent = true } diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index f21ce4fda7..74cf15ca33 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -597,8 +597,8 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) { statusWritten := false writeStatusCode := func(code int) { if !statusWritten { - w.WriteHeader(code) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(code) flush() statusWritten = true } diff --git a/pkg/api/handlers/libpod/images_pull.go b/pkg/api/handlers/libpod/images_pull.go index f2402f32ea..32471a3dcb 100644 --- a/pkg/api/handlers/libpod/images_pull.go +++ b/pkg/api/handlers/libpod/images_pull.go @@ -152,8 +152,8 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) { } } - w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) flush() enc := json.NewEncoder(w) diff --git a/pkg/api/handlers/libpod/images_push.go b/pkg/api/handlers/libpod/images_push.go index 5c3fca95a7..e3e4135dfe 100644 --- a/pkg/api/handlers/libpod/images_push.go +++ b/pkg/api/handlers/libpod/images_push.go @@ -138,8 +138,8 @@ func PushImage(w http.ResponseWriter, r *http.Request) { } } - w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) flush() enc := json.NewEncoder(w) diff --git a/pkg/api/handlers/libpod/manifests.go b/pkg/api/handlers/libpod/manifests.go index 36a324c843..40a059e336 100644 --- a/pkg/api/handlers/libpod/manifests.go +++ b/pkg/api/handlers/libpod/manifests.go @@ -451,8 +451,8 @@ func ManifestPush(w http.ResponseWriter, r *http.Request) { } } - w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) flush() enc := json.NewEncoder(w) diff --git a/pkg/api/handlers/utils/images.go b/pkg/api/handlers/utils/images.go index c67d26d7cd..6f3c96c86a 100644 --- a/pkg/api/handlers/utils/images.go +++ b/pkg/api/handlers/utils/images.go @@ -146,8 +146,8 @@ func CompatPull(ctx context.Context, w http.ResponseWriter, runtime *libpod.Runt statusWritten := false writeStatusCode := func(code int) { if !statusWritten { - w.WriteHeader(code) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(code) flush() statusWritten = true }