Skip to content

Commit

Permalink
fix(halo/app): do not override the http status header (omni-network#2283
Browse files Browse the repository at this point in the history
)

We're currently setting the http status code twice when the server is
unhealthy.

issue: none
  • Loading branch information
chmllr authored Oct 25, 2024
1 parent dc644a0 commit 61045a6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions halo/app/monitor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"bytes"
"context"
"net/http"
"os"
Expand Down Expand Up @@ -230,14 +231,19 @@ func startMonitoringAPI(

// Serve readiness status json at `/ready`, returning 503 if not ready.
mux.HandleFunc("/ready", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")

if ready, err := status.serialize(w); err != nil {
var body bytes.Buffer
statusCode := http.StatusOK
if ready, err := status.serialize(&body); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
} else if !ready {
w.WriteHeader(http.StatusServiceUnavailable)
statusCode = http.StatusServiceUnavailable
}

// Do writes in correct order
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
_, _ = w.Write(body.Bytes())
})

server := &http.Server{
Expand Down

0 comments on commit 61045a6

Please sign in to comment.