Skip to content

Commit

Permalink
added health_follow_redirect in active health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
aliasgar committed May 6, 2024
1 parent 42e9dfd commit 86ef3a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
10 changes: 0 additions & 10 deletions cmd/caddy/Caddfile

This file was deleted.

7 changes: 7 additions & 0 deletions modules/caddyhttp/reverseproxy/caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}
h.HealthChecks.Active.ExpectBody = d.Val()

case "health_follow_redirects":
if d.NextArg() {
return d.ArgErr()
}
h.HealthChecks.Active.HealthFollowRedirects = true

case "health_passes":
if !d.NextArg() {
return d.ArgErr()
Expand Down Expand Up @@ -644,6 +650,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
h.TrustedProxies = append(h.TrustedProxies, d.Val())
}


case "header_up":
var err error

Expand Down
10 changes: 9 additions & 1 deletion modules/caddyhttp/reverseproxy/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ type ActiveHealthChecks struct {
// HTTP headers to set on health check requests.
Headers http.Header `json:"headers,omitempty"`

// boolean to follow redirects in health checks disabled by default
HealthFollowRedirects bool `json:"health_follow_redirects,omitempty"`

// How frequently to perform active health checks (default 30s).
Interval caddy.Duration `json:"interval,omitempty"`

Expand Down Expand Up @@ -155,7 +158,12 @@ func (a *ActiveHealthChecks) Provision(ctx caddy.Context, h *Handler) error {
Timeout: timeout,
Transport: h.Transport,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return errors.New("Cannot redirect")
if !a.HealthFollowRedirects {
return errors.New(
"Redirects are disabled in health check, set health_follow_redirects flag in config to avoid this error")
} else {
return nil
}
},
}

Expand Down

0 comments on commit 86ef3a7

Please sign in to comment.