summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesper Brix Rosenkilde <jbr@humppa.dk>2024-07-11 15:24:13 +0200
committerGitHub <noreply@github.com>2024-07-11 09:24:13 -0400
commitdc2a5d5c52b3baeac182311fe7473870e671126a (patch)
treec378b1afab53f74feec75d64c2c66d3f28468d9e
parent4943a4fc527f41e32c1770164b00980b4226f7c7 (diff)
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
-rw-r--r--modules/caddyhttp/reverseproxy/healthchecks.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go
index 30ed0418..adb1bf5e 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)
}