From dc2a5d5c52b3baeac182311fe7473870e671126a Mon Sep 17 00:00:00 2001 From: Jesper Brix Rosenkilde Date: Thu, 11 Jul 2024 15:24:13 +0200 Subject: reverseproxy: Configurable method for active health checks (#6453) * Add option to set which HTTP method to use for active health checks * Default Method to GET if not set --- modules/caddyhttp/reverseproxy/healthchecks.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go index 30ed04185..adb1bf5e8 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"` + // The HTTP method to use for health checks (default "GET"). + Method string `json:"method,omitempty"` + // Whether to follow HTTP redirects in response to active health checks (default off). FollowRedirects bool `json:"follow_redirects,omitempty"` @@ -133,6 +136,11 @@ func (a *ActiveHealthChecks) Provision(ctx caddy.Context, h *Handler) error { } a.Headers = cleaned + // If Method is not set, default to GET + if a.Method == "" { + a.Method = http.MethodGet + } + h.HealthChecks.Active.logger = h.logger.Named("health_checker.active") timeout := time.Duration(a.Timeout) @@ -377,7 +385,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, networ ctx = context.WithValue(ctx, caddyhttp.VarsCtxKey, map[string]any{ dialInfoVarKey: dialInfo, }) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) + req, err := http.NewRequestWithContext(ctx, h.HealthChecks.Active.Method, u.String(), nil) if err != nil { return fmt.Errorf("making request: %v", err) } -- cgit v1.2.3