MCPcopy Index your code
hub / github.com/VictoriaMetrics/VictoriaLogs / CheckBasicAuth

Function CheckBasicAuth

lib/httpserver/httpserver.go:485–501  ·  view source on GitHub ↗

CheckBasicAuth validates credentials provided in request if httpAuth.* flags are set returns true if credentials are valid or httpAuth.* flags are not set

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

483// CheckBasicAuth validates credentials provided in request if httpAuth.* flags are set
484// returns true if credentials are valid or httpAuth.* flags are not set
485func CheckBasicAuth(w http.ResponseWriter, r *http.Request) bool {
486 if len(*httpAuthUsername) == 0 {
487 // HTTP Basic Auth is disabled.
488 return true
489 }
490 username, password, ok := r.BasicAuth()
491 if ok {
492 if username == *httpAuthUsername && password == httpAuthPassword.Get() {
493 return true
494 }
495 authBasicRequestErrors.Inc()
496 }
497
498 w.Header().Set("WWW-Authenticate", `Basic realm="VictoriaMetrics"`)
499 http.Error(w, "", http.StatusUnauthorized)
500 return false
501}
502
503// EnableCORS enables https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
504// on the response.

Callers 4

newRequestHandlerFunction · 0.92
TestBasicAuthMetricsFunction · 0.85
builtinRoutesHandlerFunction · 0.85
CheckAuthFlagFunction · 0.85

Calls 4

HeaderMethod · 0.80
GetMethod · 0.45
SetMethod · 0.45
ErrorMethod · 0.45

Tested by 1

TestBasicAuthMetricsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…