aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/reverseproxy/healthchecks.go
diff options
context:
space:
mode:
authorAli Asgar <[email protected]>2024-05-07 20:10:15 +0530
committerGitHub <[email protected]>2024-05-07 08:40:15 -0600
commitb2b29dcd4956c9fa722daf6d31fc22aea74ed4fb (patch)
tree577f6b166b99723f4e6b86b0ef61393b2ff3fd1d /modules/caddyhttp/reverseproxy/healthchecks.go
parentc97292b255c144dfa9f1ea1dfcdec3b82717110d (diff)
downloadcaddy-b2b29dcd4956c9fa722daf6d31fc22aea74ed4fb.tar.gz
caddy-b2b29dcd4956c9fa722daf6d31fc22aea74ed4fb.zip
reverseproxy: Implement health_follow_redirects (#6302)
* added health_follow_redirect in active health checks * chore: code format * chore: refactore reversproxy healthcheck redirect variable name and description of the same * chore: formatting * changed reverse proxy health check status code range to be between 200-299 * chore: formatting --------- Co-authored-by: aliasgar <[email protected]>
Diffstat (limited to 'modules/caddyhttp/reverseproxy/healthchecks.go')
-rw-r--r--modules/caddyhttp/reverseproxy/healthchecks.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go
index 507e67c88..90db9b340 100644
--- a/modules/caddyhttp/reverseproxy/healthchecks.go
+++ b/modules/caddyhttp/reverseproxy/healthchecks.go
@@ -82,6 +82,9 @@ type ActiveHealthChecks struct {
// HTTP headers to set on health check requests.
Headers http.Header `json:"headers,omitempty"`
+ // Whether to follow HTTP redirects in response to active health checks (default off).
+ FollowRedirects bool `json:"follow_redirects,omitempty"`
+
// How frequently to perform active health checks (default 30s).
Interval caddy.Duration `json:"interval,omitempty"`
@@ -153,6 +156,12 @@ func (a *ActiveHealthChecks) Provision(ctx caddy.Context, h *Handler) error {
a.httpClient = &http.Client{
Timeout: timeout,
Transport: h.Transport,
+ CheckRedirect: func(req *http.Request, via []*http.Request) error {
+ if !a.FollowRedirects {
+ return http.ErrUseLastResponse
+ }
+ return nil
+ },
}
for _, upstream := range h.Upstreams {
@@ -453,7 +462,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, upstre
markUnhealthy()
return nil
}
- } else if resp.StatusCode < 200 || resp.StatusCode >= 400 {
+ } else if resp.StatusCode < 200 || resp.StatusCode >= 300 {
h.HealthChecks.Active.logger.Info("status code out of tolerances",
zap.Int("status_code", resp.StatusCode),
zap.String("host", hostAddr),