diff --git a/pkg/modules/api/api.go b/pkg/modules/api/api.go index 7b3370bd..9e8feca7 100644 --- a/pkg/modules/api/api.go +++ b/pkg/modules/api/api.go @@ -453,13 +453,22 @@ func (a *Api) Start() error { ) } - // Let's not forget the health check route... + // Let's not forget the health check routes... + checks := append(a.healthChecks, health.WithTimeout(a.timeout)) + checker := health.NewChecker(checks...) + healthCheckHandler := health.NewHandler(checker) + a.srv.GET( fmt.Sprintf("%s%s", a.rootPath, "health"), func() echo.HandlerFunc { - checks := append(a.healthChecks, health.WithTimeout(a.timeout)) - checker := health.NewChecker(checks...) - return echo.WrapHandler(health.NewHandler(checker)) + return echo.WrapHandler(healthCheckHandler) + }(), + hardTimeoutMiddleware(hardTimeout), + ) + a.srv.HEAD( + fmt.Sprintf("%s%s", a.rootPath, "health"), + func() echo.HandlerFunc { + return echo.WrapHandler(healthCheckHandler) }(), hardTimeoutMiddleware(hardTimeout), ) diff --git a/pkg/modules/api/api_test.go b/pkg/modules/api/api_test.go index c82a4c05..8e8a4615 100644 --- a/pkg/modules/api/api_test.go +++ b/pkg/modules/api/api_test.go @@ -839,18 +839,23 @@ func TestApi_Start(t *testing.T) { return } - // health request. + // health requests. recorder := httptest.NewRecorder() - healthRequest := httptest.NewRequest(http.MethodGet, "/health", nil) - mod.srv.ServeHTTP(recorder, healthRequest) + healthGetRequest := httptest.NewRequest(http.MethodGet, "/health", nil) + mod.srv.ServeHTTP(recorder, healthGetRequest) + if recorder.Code != http.StatusOK { + t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code) + } + + healthHeadRequest := httptest.NewRequest(http.MethodHead, "/health", nil) + mod.srv.ServeHTTP(recorder, healthHeadRequest) if recorder.Code != http.StatusOK { t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code) } // version request. versionRequest := httptest.NewRequest(http.MethodGet, "/version", nil) - mod.srv.ServeHTTP(recorder, versionRequest) if recorder.Code != http.StatusOK { t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code) @@ -859,7 +864,6 @@ func TestApi_Start(t *testing.T) { // "multipart/form-data" request. multipartRequest := func(url string) *http.Request { body := &bytes.Buffer{} - writer := multipart.NewWriter(body) defer func() {