Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
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.
Matthew Holt committed
Mar 27, 2020 at 14:29 UTC
e207240f9a6def2e29abf0947a660ab84f858016
2 files changed
+10
-2
modules/caddyhttp/reverseproxy/hosts.go
+7
@@ -96,6 +96,13 @@ type Upstream struct {
96
cb CircuitBreaker
97
}
98
99
+func (u Upstream) String() string {
100
+ if u.LookupSRV != "" {
101
+ return u.LookupSRV
102
+ }
103
+ return u.Dial
104
+}
105
+
106
// Available returns true if the remote host
107
// is available to receive requests. This is
108
// the method that should be used by selection
modules/caddyhttp/reverseproxy/reverseproxy.go
+3
-2
@@ -172,7 +172,7 @@ func (h *Handler) Provision(ctx caddy.Context) error {
172
for _, upstream := range h.Upstreams {
173
// create or get the host representation for this upstream
174
var host Host = new(upstreamHost)
175
- existingHost, loaded := hosts.LoadOrStore(upstream.Dial, host)
175
+ existingHost, loaded := hosts.LoadOrStore(upstream.String(), host)
176
if loaded {
177
host = existingHost.(Host)
178
}
@@ -252,7 +252,7 @@ func (h *Handler) Cleanup() error {
252
253
// remove hosts from our config from the pool
254
for _, upstream := range h.Upstreams {
255
- hosts.Delete(upstream.Dial)
255
+ hosts.Delete(upstream.String())
256
}
257
258
return nil
@@ -446,6 +446,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, di Dia
446
}
447
448
h.logger.Debug("upstream roundtrip",
449
+ zap.String("upstream", di.Upstream.String()),
450
zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: req}),
451
zap.Object("headers", caddyhttp.LoggableHTTPHeader(res.Header)),
452
zap.Duration("duration", duration),