Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 10:45 UTC
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
Jesper Brix Rosenkilde committed
Jul 11, 2024 at 15:24 UTC
dc2a5d5c52b3baeac182311fe7473870e671126a
1 file changed
+9
-1
modules/caddyhttp/reverseproxy/healthchecks.go
+9
-1
@@ -82,6 +82,9 @@ type ActiveHealthChecks struct {
82
// HTTP headers to set on health check requests.
83
Headers http.Header `json:"headers,omitempty"`
84
85
+ // The HTTP method to use for health checks (default "GET").
86
+ Method string `json:"method,omitempty"`
87
+
88
// Whether to follow HTTP redirects in response to active health checks (default off).
89
FollowRedirects bool `json:"follow_redirects,omitempty"`
90
@@ -133,6 +136,11 @@ func (a *ActiveHealthChecks) Provision(ctx caddy.Context, h *Handler) error {
136
}
137
a.Headers = cleaned
138
139
+ // If Method is not set, default to GET
140
+ if a.Method == "" {
141
+ a.Method = http.MethodGet
142
+ }
143
+
144
h.HealthChecks.Active.logger = h.logger.Named("health_checker.active")
145
146
timeout := time.Duration(a.Timeout)
@@ -377,7 +385,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, networ
385
ctx = context.WithValue(ctx, caddyhttp.VarsCtxKey, map[string]any{
386
dialInfoVarKey: dialInfo,
387
})
380
- req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
388
+ req, err := http.NewRequestWithContext(ctx, h.HealthChecks.Active.Method, u.String(), nil)
389
if err != nil {
390
return fmt.Errorf("making request: %v", err)
391
}