From 388f61aed69c0b00c5de1a7f97fb33ddc286eb51 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sat, 10 Feb 2024 10:59:39 +0200 Subject: [PATCH] [#4310] allow HEAD requests to the health endpoint --- CHANGELOG.md | 4 +++- apis/health.go | 5 +++++ apis/health_test.go | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9daa6e2f..148c6528 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## (WIP) v0.21.3 -- Disable the JS required validations for disabled OIDC providers ([#4322](https://github.com/pocketbase/pocketbase/issues/4322)). +- Ignore the JS required validations for disabled OIDC providers ([#4322](https://github.com/pocketbase/pocketbase/issues/4322)). + +- Allow `HEAD` requests to the `/api/health` endpoint ([#4310](https://github.com/pocketbase/pocketbase/issues/4310)). ## v0.21.2 diff --git a/apis/health.go b/apis/health.go index 9b6e0c88..92b913c8 100644 --- a/apis/health.go +++ b/apis/health.go @@ -12,6 +12,7 @@ func bindHealthApi(app core.App, rg *echo.Group) { api := healthApi{app: app} subGroup := rg.Group("/health") + subGroup.HEAD("", api.healthCheck) subGroup.GET("", api.healthCheck) } @@ -29,6 +30,10 @@ type healthCheckResponse struct { // healthCheck returns a 200 OK response if the server is healthy. func (api *healthApi) healthCheck(c echo.Context) error { + if c.Request().Method == http.MethodHead { + return c.NoContent(http.StatusOK) + } + resp := new(healthCheckResponse) resp.Code = http.StatusOK resp.Message = "API is healthy." diff --git a/apis/health_test.go b/apis/health_test.go index a86961d1..6afed6bf 100644 --- a/apis/health_test.go +++ b/apis/health_test.go @@ -12,7 +12,13 @@ func TestHealthAPI(t *testing.T) { scenarios := []tests.ApiScenario{ { - Name: "health status returns 200", + Name: "HEAD health status", + Method: http.MethodHead, + Url: "/api/health", + ExpectedStatus: 200, + }, + { + Name: "GET health status", Method: http.MethodGet, Url: "/api/health", ExpectedStatus: 200,