mirror of
https://github.com/fosrl/olm.git
synced 2026-03-01 16:26:43 +00:00
add content-length header to status payload
This commit is contained in:
14
api/api.go
14
api/api.go
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user