fix: set header fields before response status code to prevent missing fields

Signed-off-by: Anders Hausding <anders.hausding@siemens.com>
This commit is contained in:
Anders Hausding
2025-08-25 13:29:48 +02:00
parent b6d92f7df5
commit 8566ef71c0
7 changed files with 7 additions and 7 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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
}