summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/reverseproxy.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-03-29 20:36:40 -0400
committerGitHub <noreply@github.com>2021-03-29 18:36:40 -0600
commit75f797debdd6c4294497edba9889c6251a8542e7 (patch)
tree7146a299bbc84ace3df9d57ba9ac6febb984f818 /modules/caddyhttp/reverseproxy/reverseproxy.go
parent1c8ea0082822fbc13cb6b86443b908f6a068f385 (diff)
reverseproxy: Implement health_uri, deprecate health_path, supports query (#4050)
* reverseproxy: Implement health_uri, replaces health_path, supports query Also fixes a bug with `health_status` Caddyfile parsing , it would always only take the first character of the status code even if it didn't end with "xx". * reverseproxy: Rename to URI, named logger, warn in Provision (for JSON)
Diffstat (limited to 'modules/caddyhttp/reverseproxy/reverseproxy.go')
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index 9da509f..b552d96 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -23,6 +23,7 @@ import (
"io"
"net"
"net/http"
+ "net/url"
"regexp"
"strconv"
"strings"
@@ -273,8 +274,10 @@ func (h *Handler) Provision(ctx caddy.Context) error {
}
// if active health checks are enabled, configure them and start a worker
- if h.HealthChecks.Active != nil &&
- (h.HealthChecks.Active.Path != "" || h.HealthChecks.Active.Port != 0) {
+ if h.HealthChecks.Active != nil && (h.HealthChecks.Active.Path != "" ||
+ h.HealthChecks.Active.URI != "" ||
+ h.HealthChecks.Active.Port != 0) {
+
h.HealthChecks.Active.logger = h.logger.Named("health_checker.active")
timeout := time.Duration(h.HealthChecks.Active.Timeout)
@@ -282,6 +285,19 @@ func (h *Handler) Provision(ctx caddy.Context) error {
timeout = 5 * time.Second
}
+ if h.HealthChecks.Active.Path != "" {
+ h.HealthChecks.Active.logger.Warn("the 'path' option is deprecated, please use 'uri' instead!")
+ }
+
+ // parse the URI string (supports path and query)
+ if h.HealthChecks.Active.URI != "" {
+ parsedURI, err := url.Parse(h.HealthChecks.Active.URI)
+ if err != nil {
+ return err
+ }
+ h.HealthChecks.Active.uri = parsedURI
+ }
+
h.HealthChecks.Active.httpClient = &http.Client{
Timeout: timeout,
Transport: h.Transport,