MCPcopy Index your code
hub / github.com/InferCore/InferCore / withOptionalInfercoreAuth

Method withOptionalInfercoreAuth

internal/server/server.go:172–185  ·  view source on GitHub ↗
(next http.Handler)

Source from the content-addressed store, hash-verified

170}
171
172func (s *Server) withOptionalInfercoreAuth(next http.Handler) http.Handler {
173 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
174 key := s.effectiveInfercoreAPIKey()
175 if key == "" || r.URL.Path == "/health" {
176 next.ServeHTTP(w, r)
177 return
178 }
179 if !infercoreAuthOK(r, key) {
180 writeError(w, http.StatusUnauthorized, "", errCodeUnauthorized, "invalid or missing API key")
181 return
182 }
183 next.ServeHTTP(w, r)
184 })
185}
186
187func infercoreAuthOK(r *http.Request, want string) bool {
188 if v := strings.TrimSpace(r.Header.Get("X-InferCore-Api-Key")); v != "" && v == want {

Callers 1

RoutesMethod · 0.95

Calls 3

infercoreAuthOKFunction · 0.85
writeErrorFunction · 0.85

Tested by

no test coverage detected