mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 12:22:17 +01:00
feat(api): add HEAD method for health route (#963)
This commit is contained in:
@@ -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(
|
a.srv.GET(
|
||||||
fmt.Sprintf("%s%s", a.rootPath, "health"),
|
fmt.Sprintf("%s%s", a.rootPath, "health"),
|
||||||
func() echo.HandlerFunc {
|
func() echo.HandlerFunc {
|
||||||
checks := append(a.healthChecks, health.WithTimeout(a.timeout))
|
return echo.WrapHandler(healthCheckHandler)
|
||||||
checker := health.NewChecker(checks...)
|
}(),
|
||||||
return echo.WrapHandler(health.NewHandler(checker))
|
hardTimeoutMiddleware(hardTimeout),
|
||||||
|
)
|
||||||
|
a.srv.HEAD(
|
||||||
|
fmt.Sprintf("%s%s", a.rootPath, "health"),
|
||||||
|
func() echo.HandlerFunc {
|
||||||
|
return echo.WrapHandler(healthCheckHandler)
|
||||||
}(),
|
}(),
|
||||||
hardTimeoutMiddleware(hardTimeout),
|
hardTimeoutMiddleware(hardTimeout),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -839,18 +839,23 @@ func TestApi_Start(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// health request.
|
// health requests.
|
||||||
recorder := httptest.NewRecorder()
|
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 {
|
if recorder.Code != http.StatusOK {
|
||||||
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
// version request.
|
// version request.
|
||||||
versionRequest := httptest.NewRequest(http.MethodGet, "/version", nil)
|
versionRequest := httptest.NewRequest(http.MethodGet, "/version", nil)
|
||||||
|
|
||||||
mod.srv.ServeHTTP(recorder, versionRequest)
|
mod.srv.ServeHTTP(recorder, versionRequest)
|
||||||
if recorder.Code != http.StatusOK {
|
if recorder.Code != http.StatusOK {
|
||||||
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
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.
|
// "multipart/form-data" request.
|
||||||
multipartRequest := func(url string) *http.Request {
|
multipartRequest := func(url string) *http.Request {
|
||||||
body := &bytes.Buffer{}
|
body := &bytes.Buffer{}
|
||||||
|
|
||||||
writer := multipart.NewWriter(body)
|
writer := multipart.NewWriter(body)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user