summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/hosts.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/reverseproxy/hosts.go')
-rw-r--r--modules/caddyhttp/reverseproxy/hosts.go67
1 files changed, 26 insertions, 41 deletions
diff --git a/modules/caddyhttp/reverseproxy/hosts.go b/modules/caddyhttp/reverseproxy/hosts.go
index a973ecb..83a39d8 100644
--- a/modules/caddyhttp/reverseproxy/hosts.go
+++ b/modules/caddyhttp/reverseproxy/hosts.go
@@ -17,8 +17,8 @@ package reverseproxy
import (
"context"
"fmt"
- "net"
"net/http"
+ "net/netip"
"strconv"
"sync/atomic"
@@ -47,15 +47,6 @@ type Upstream struct {
// backends is down. Also be aware of open proxy vulnerabilities.
Dial string `json:"dial,omitempty"`
- // DEPRECATED: Use the SRVUpstreams module instead
- // (http.reverse_proxy.upstreams.srv). This field will be
- // removed in a future version of Caddy. TODO: Remove this field.
- //
- // If DNS SRV records are used for service discovery with this
- // upstream, specify the DNS name for which to look up SRV
- // records here, instead of specifying a dial address.
- LookupSRV string `json:"lookup_srv,omitempty"`
-
// The maximum number of simultaneous requests to allow to
// this upstream. If set, overrides the global passive health
// check UnhealthyRequestCount value.
@@ -72,12 +63,10 @@ type Upstream struct {
unhealthy int32 // accessed atomically; status from active health checker
}
-func (u Upstream) String() string {
- if u.LookupSRV != "" {
- return u.LookupSRV
- }
- return u.Dial
-}
+// (pointer receiver necessary to avoid a race condition, since
+// copying the Upstream reads the 'unhealthy' field which is
+// accessed atomically)
+func (u *Upstream) String() string { return u.Dial }
// Available returns true if the remote host
// is available to receive requests. This is
@@ -109,35 +98,21 @@ func (u *Upstream) Full() bool {
}
// fillDialInfo returns a filled DialInfo for upstream u, using the request
-// context. If the upstream has a SRV lookup configured, that is done and a
-// returned address is chosen; otherwise, the upstream's regular dial address
-// field is used. Note that the returned value is not a pointer.
+// context. Note that the returned value is not a pointer.
func (u *Upstream) fillDialInfo(r *http.Request) (DialInfo, error) {
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
var addr caddy.NetworkAddress
- if u.LookupSRV != "" {
- // perform DNS lookup for SRV records and choose one - TODO: deprecated
- srvName := repl.ReplaceAll(u.LookupSRV, "")
- _, records, err := net.DefaultResolver.LookupSRV(r.Context(), "", "", srvName)
- if err != nil {
- return DialInfo{}, err
- }
- addr.Network = "tcp"
- addr.Host = records[0].Target
- addr.StartPort, addr.EndPort = uint(records[0].Port), uint(records[0].Port)
- } else {
- // use provided dial address
- var err error
- dial := repl.ReplaceAll(u.Dial, "")
- addr, err = caddy.ParseNetworkAddress(dial)
- if err != nil {
- return DialInfo{}, fmt.Errorf("upstream %s: invalid dial address %s: %v", u.Dial, dial, err)
- }
- if numPorts := addr.PortRangeSize(); numPorts != 1 {
- return DialInfo{}, fmt.Errorf("upstream %s: dial address must represent precisely one socket: %s represents %d",
- u.Dial, dial, numPorts)
- }
+ // use provided dial address
+ var err error
+ dial := repl.ReplaceAll(u.Dial, "")
+ addr, err = caddy.ParseNetworkAddress(dial)
+ if err != nil {
+ return DialInfo{}, fmt.Errorf("upstream %s: invalid dial address %s: %v", u.Dial, dial, err)
+ }
+ if numPorts := addr.PortRangeSize(); numPorts != 1 {
+ return DialInfo{}, fmt.Errorf("upstream %s: dial address must represent precisely one socket: %s represents %d",
+ u.Dial, dial, numPorts)
}
return DialInfo{
@@ -259,3 +234,13 @@ var hosts = caddy.NewUsagePool()
// dialInfoVarKey is the key used for the variable that holds
// the dial info for the upstream connection.
const dialInfoVarKey = "reverse_proxy.dial_info"
+
+// proxyProtocolInfoVarKey is the key used for the variable that holds
+// the proxy protocol info for the upstream connection.
+const proxyProtocolInfoVarKey = "reverse_proxy.proxy_protocol_info"
+
+// ProxyProtocolInfo contains information needed to write proxy protocol to a
+// connection to an upstream host.
+type ProxyProtocolInfo struct {
+ AddrPort netip.AddrPort
+}