mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
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
This commit is contained in:
parent
4943a4fc52
commit
dc2a5d5c52
1 changed files with 9 additions and 1 deletions
|
@ -82,6 +82,9 @@ type ActiveHealthChecks struct {
|
||||||
// HTTP headers to set on health check requests.
|
// HTTP headers to set on health check requests.
|
||||||
Headers http.Header `json:"headers,omitempty"`
|
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).
|
// Whether to follow HTTP redirects in response to active health checks (default off).
|
||||||
FollowRedirects bool `json:"follow_redirects,omitempty"`
|
FollowRedirects bool `json:"follow_redirects,omitempty"`
|
||||||
|
|
||||||
|
@ -133,6 +136,11 @@ func (a *ActiveHealthChecks) Provision(ctx caddy.Context, h *Handler) error {
|
||||||
}
|
}
|
||||||
a.Headers = cleaned
|
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")
|
h.HealthChecks.Active.logger = h.logger.Named("health_checker.active")
|
||||||
|
|
||||||
timeout := time.Duration(a.Timeout)
|
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{
|
ctx = context.WithValue(ctx, caddyhttp.VarsCtxKey, map[string]any{
|
||||||
dialInfoVarKey: dialInfo,
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("making request: %v", err)
|
return fmt.Errorf("making request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue