(w http.ResponseWriter, r *http.Request)
| 254 | } |
| 255 | |
| 256 | func (st *state) pingResponse(w http.ResponseWriter, r *http.Request) { |
| 257 | x.AddCorsHeaders(w) |
| 258 | |
| 259 | /* |
| 260 | * zero is changed to also output the health in JSON format for client |
| 261 | * request header "Accept: application/json". |
| 262 | * |
| 263 | * Backward compatibility- Before this change the '/health' endpoint |
| 264 | * used to output the string OK. After the fix it returns OK when the |
| 265 | * client sends the request without "Accept: application/json" in its |
| 266 | * http header. |
| 267 | */ |
| 268 | switch r.Header.Get("Accept") { |
| 269 | case "application/json": |
| 270 | resp, err := (st.zero).zeroHealth(r.Context()) |
| 271 | if err != nil { |
| 272 | x.SetStatus(w, x.Error, err.Error()) |
| 273 | return |
| 274 | } |
| 275 | w.Header().Set("Content-Type", "application/json; charset=utf-8") |
| 276 | w.WriteHeader(http.StatusOK) |
| 277 | if _, err := w.Write(resp.Json); err != nil { |
| 278 | glog.Warningf("http error send failed, error msg=[%v]", err) |
| 279 | return |
| 280 | } |
| 281 | default: |
| 282 | w.Header().Set("Content-Type", "text/plain; charset=utf-8") |
| 283 | w.WriteHeader(http.StatusOK) |
| 284 | if _, err := w.Write([]byte("OK")); err != nil { |
| 285 | glog.Warningf("http error send failed, error msg=[%v]", err) |
| 286 | return |
| 287 | } |
| 288 | } |
| 289 | } |
nothing calls this directly
no test coverage detected