Skip to content

Commit 2ee48a5

Browse files
committed
Fix json content-type not being set in HTTPHandler due to headers already sent
1 parent d51f9de commit 2ee48a5

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

handler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ func HTTPHandler(hc HealthChecker) http.Handler {
2929
if hc == nil {
3030
panic(panicNilHealthChecker)
3131
}
32+
3233
if checker, ok := hc.(*Checker); ok {
3334
return http.HandlerFunc(func(wri http.ResponseWriter, req *http.Request) {
3435
stat := checker.CheckHealth(req.Context())
35-
wri.WriteHeader(stat.StatusCode())
36-
3736
if stat == StatusHealthy {
37+
wri.WriteHeader(stat.StatusCode())
3838
_, _ = wri.Write(okBytes)
3939
} else {
4040
wri.Header().Set("Content-Type", "application/json")
41+
wri.WriteHeader(stat.StatusCode())
4142
_ = json.NewEncoder(wri).Encode(checker.Details())
4243
}
4344
})

0 commit comments

Comments
 (0)