summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/hosts.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-05 13:14:39 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-05 13:14:39 -0600
commit0830fbad0347ead1dbea60e664556b263e44653f (patch)
tree8c982d945587b083cfe4c57b1858af2f5f1cc338 /modules/caddyhttp/reverseproxy/hosts.go
parenta60d54dbfd93f74187b4051f1522c42d34480503 (diff)
Reconcile upstream dial addresses and request host/URL information
My goodness that was complicated Blessed be request.Context Sort of
Diffstat (limited to 'modules/caddyhttp/reverseproxy/hosts.go')
-rw-r--r--modules/caddyhttp/reverseproxy/hosts.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/modules/caddyhttp/reverseproxy/hosts.go b/modules/caddyhttp/reverseproxy/hosts.go
index b40e614..ad27625 100644
--- a/modules/caddyhttp/reverseproxy/hosts.go
+++ b/modules/caddyhttp/reverseproxy/hosts.go
@@ -16,7 +16,6 @@ package reverseproxy
import (
"fmt"
- "net/url"
"sync/atomic"
"github.com/caddyserver/caddy/v2"
@@ -59,7 +58,7 @@ type UpstreamPool []*Upstream
type Upstream struct {
Host `json:"-"`
- Address string `json:"address,omitempty"`
+ Dial string `json:"dial,omitempty"`
MaxRequests int `json:"max_requests,omitempty"`
// TODO: This could be really useful, to bind requests
@@ -68,8 +67,8 @@ type Upstream struct {
// IPAffinity string
healthCheckPolicy *PassiveHealthChecks
- hostURL *url.URL
cb CircuitBreaker
+ dialInfo DialInfo
}
// Available returns true if the remote host
@@ -101,11 +100,6 @@ func (u *Upstream) Full() bool {
return u.MaxRequests > 0 && u.Host.NumRequests() >= u.MaxRequests
}
-// URL returns the upstream host's endpoint URL.
-func (u *Upstream) URL() *url.URL {
- return u.hostURL
-}
-
// upstreamHost is the basic, in-memory representation
// of the state of a remote host. It implements the
// Host interface.
@@ -162,6 +156,34 @@ func (uh *upstreamHost) SetHealthy(healthy bool) (bool, error) {
return swapped, nil
}
+// DialInfo contains information needed to dial a
+// connection to an upstream host. This information
+// may be different than that which is represented
+// in a URL (for example, unix sockets don't have
+// a host that can be represented in a URL, but
+// they certainly have a network name and address).
+type DialInfo struct {
+ // The network to use. This should be one of the
+ // values that is accepted by net.Dial:
+ // https://golang.org/pkg/net/#Dial
+ Network string
+
+ // The address to dial. Follows the same
+ // semantics and rules as net.Dial.
+ Address string
+}
+
+// String returns the Caddy network address form
+// by joining the network and address with a
+// forward slash.
+func (di DialInfo) String() string {
+ return di.Network + "/" + di.Address
+}
+
+// DialInfoCtxKey is used to store a DialInfo
+// in a context.Context.
+const DialInfoCtxKey = caddy.CtxKey("dial_info")
+
// hosts is the global repository for hosts that are
// currently in use by active configuration(s). This
// allows the state of remote hosts to be preserved