diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-03-27 14:29:01 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-03-27 14:29:01 -0600 |
commit | e207240f9a6def2e29abf0947a660ab84f858016 (patch) | |
tree | b9d09ddcc16246d5efad84ed29623481a38f9f41 /modules/caddyhttp/reverseproxy | |
parent | 397e04ebd9802d711a109822c3304bdf87b3a1ce (diff) |
reverse_proxy: Upstream.String() method returns either LookupSRV or Dial
Either Dial or LookupSRV will be set, but if we rely on Dial always
being set, we could run into bugs.
Note: Health checks don't support SRV upstreams.
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-rw-r--r-- | modules/caddyhttp/reverseproxy/hosts.go | 7 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/reverseproxy.go | 5 |
2 files changed, 10 insertions, 2 deletions
diff --git a/modules/caddyhttp/reverseproxy/hosts.go b/modules/caddyhttp/reverseproxy/hosts.go index a7709ee..87139c3 100644 --- a/modules/caddyhttp/reverseproxy/hosts.go +++ b/modules/caddyhttp/reverseproxy/hosts.go @@ -96,6 +96,13 @@ type Upstream struct { cb CircuitBreaker } +func (u Upstream) String() string { + if u.LookupSRV != "" { + return u.LookupSRV + } + return u.Dial +} + // Available returns true if the remote host // is available to receive requests. This is // the method that should be used by selection diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index 918f7a6..4ac50ac 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -172,7 +172,7 @@ func (h *Handler) Provision(ctx caddy.Context) error { for _, upstream := range h.Upstreams { // create or get the host representation for this upstream var host Host = new(upstreamHost) - existingHost, loaded := hosts.LoadOrStore(upstream.Dial, host) + existingHost, loaded := hosts.LoadOrStore(upstream.String(), host) if loaded { host = existingHost.(Host) } @@ -252,7 +252,7 @@ func (h *Handler) Cleanup() error { // remove hosts from our config from the pool for _, upstream := range h.Upstreams { - hosts.Delete(upstream.Dial) + hosts.Delete(upstream.String()) } return nil @@ -446,6 +446,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, di Dia } h.logger.Debug("upstream roundtrip", + zap.String("upstream", di.Upstream.String()), zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: req}), zap.Object("headers", caddyhttp.LoggableHTTPHeader(res.Header)), zap.Duration("duration", duration), |