(next http.Handler)
| 170 | } |
| 171 | |
| 172 | func (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 | |
| 187 | func infercoreAuthOK(r *http.Request, want string) bool { |
| 188 | if v := strings.TrimSpace(r.Header.Get("X-InferCore-Api-Key")); v != "" && v == want { |
no test coverage detected