MCPcopy
hub / github.com/dgraph-io/dgraph / pingResponse

Method pingResponse

dgraph/cmd/zero/http.go:256–289  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

254}
255
256func (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}

Callers

nothing calls this directly

Calls 9

AddCorsHeadersFunction · 0.92
SetStatusFunction · 0.92
zeroHealthMethod · 0.80
WarningfMethod · 0.80
GetMethod · 0.65
SetMethod · 0.65
WriteHeaderMethod · 0.65
WriteMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected