diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-03-07 21:29:05 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-04-20 17:38:08 +0300 |
commit | 01bc799b99fcc5e60292293dfcafda8013cf60ff (patch) | |
tree | b7b4cfb59834716534eb2724271a9e69d9fdb166 /app.go | |
parent | dabfd71101d4598f31ab474f6a7bfc75bfa0a045 (diff) |
Move healthcheck middleware to a separate package
add Cache-Control: no-store to status response
Diffstat (limited to 'app.go')
-rw-r--r-- | app.go | 32 |
1 files changed, 2 insertions, 30 deletions
@@ -30,6 +30,7 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/domain" "gitlab.com/gitlab-org/gitlab-pages/internal/errortracking" "gitlab.com/gitlab-org/gitlab-pages/internal/handlers" + health "gitlab.com/gitlab-org/gitlab-pages/internal/healthcheck" "gitlab.com/gitlab-org/gitlab-pages/internal/httperrors" "gitlab.com/gitlab-org/gitlab-pages/internal/logging" "gitlab.com/gitlab-org/gitlab-pages/internal/netutil" @@ -59,10 +60,6 @@ type theApp struct { CustomHeaders http.Header } -func (a *theApp) isReady() bool { - return true -} - func (a *theApp) GetCertificate(ch *cryptotls.ClientHelloInfo) (*cryptotls.Certificate, error) { if ch.ServerName == "" { return nil, nil @@ -127,11 +124,6 @@ func (a *theApp) tryAuxiliaryHandlers(w http.ResponseWriter, r *http.Request, ht return true } - if !a.isReady() { - httperrors.Serve503(w) - return true - } - if _, err := domain.GetLookupPath(r); err != nil { if errors.Is(err, gitlab.ErrDiskDisabled) { errortracking.CaptureErrWithReqAndStackTrace(err, r) @@ -152,26 +144,6 @@ func (a *theApp) tryAuxiliaryHandlers(w http.ResponseWriter, r *http.Request, ht return false } -// healthCheckMiddleware is serving the application status check -func (a *theApp) healthCheckMiddleware(handler http.Handler) http.Handler { - healthCheck := http.HandlerFunc(func(w http.ResponseWriter, _r *http.Request) { - if a.isReady() { - w.Write([]byte("success\n")) - } else { - http.Error(w, "not yet ready", http.StatusServiceUnavailable) - } - }) - - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.RequestURI == a.config.General.StatusPath { - healthCheck.ServeHTTP(w, r) - return - } - - handler.ServeHTTP(w, r) - }) -} - // auxiliaryMiddleware will handle status updates, not-ready requests and other // not static-content responses func (a *theApp) auxiliaryMiddleware(handler http.Handler) http.Handler { @@ -250,7 +222,7 @@ func (a *theApp) buildHandlerPipeline() (http.Handler, error) { handler = handlers.Ratelimiter(handler, &a.config.RateLimit) // Health Check - handler = a.healthCheckMiddleware(handler) + handler = health.NewMiddleware(handler, a.config.General.StatusPath) // Custom response headers handler = customheaders.NewMiddleware(handler, a.CustomHeaders) |