feat(api): add support for HEAD requests to /healthz endpoint

- Refactored `/healthz` handler to support `HEAD` requests alongside `GET`.
- Updated tests to include validation for `HEAD` requests with expected status and empty body.

Closes: #2929
This commit is contained in:
Luis Pater
2026-04-21 20:16:18 +08:00
parent e6866ff19c
commit 1716a845eb
2 changed files with 39 additions and 17 deletions
+9 -2
View File
@@ -319,9 +319,16 @@ func NewServer(cfg *config.Config, authManager *auth.Manager, accessManager *sdk
// setupRoutes configures the API routes for the server.
// It defines the endpoints and associates them with their respective handlers.
func (s *Server) setupRoutes() {
s.engine.GET("/healthz", func(c *gin.Context) {
healthzHandler := func(c *gin.Context) {
if c.Request.Method == http.MethodHead {
c.Status(http.StatusOK)
return
}
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
}
s.engine.GET("/healthz", healthzHandler)
s.engine.HEAD("/healthz", healthzHandler)
s.engine.GET("/management.html", s.serveManagementControlPanel)
openaiHandlers := openai.NewOpenAIAPIHandler(s.handlers)