add content-length header to status payload

This commit is contained in:
miloschwartz
2025-12-29 17:28:12 -05:00
parent 6d2afb4c72
commit 8152d4133f

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"strconv"
"sync" "sync"
"time" "time"
@@ -358,7 +359,6 @@ func (s *API) handleStatus(w http.ResponseWriter, r *http.Request) {
} }
s.statusMu.RLock() s.statusMu.RLock()
defer s.statusMu.RUnlock()
resp := StatusResponse{ resp := StatusResponse{
Connected: s.isConnected, Connected: s.isConnected,
@@ -371,8 +371,18 @@ func (s *API) handleStatus(w http.ResponseWriter, r *http.Request) {
NetworkSettings: network.GetSettings(), NetworkSettings: network.GetSettings(),
} }
s.statusMu.RUnlock()
data, err := json.Marshal(resp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp) w.Header().Set("Content-Length", strconv.Itoa(len(data)))
w.WriteHeader(http.StatusOK)
_, _ = w.Write(data)
} }
// handleHealth handles the /health endpoint // handleHealth handles the /health endpoint