aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/reverseproxy/caddyfile.go
diff options
context:
space:
mode:
authorMohammed Al Sahaf <[email protected]>2023-08-05 23:30:02 +0200
committerGitHub <[email protected]>2023-08-05 23:30:02 +0200
commit65e33fc1ee4798bb3450f6e291bfc88404982636 (patch)
tree6df2a4fc05295246c3cb9ab412fbe6d2828be8fd /modules/caddyhttp/reverseproxy/caddyfile.go
parent9f34383c02f1691e54280285a6499893fcbbb4c7 (diff)
downloadcaddy-65e33fc1ee4798bb3450f6e291bfc88404982636.tar.gz
caddy-65e33fc1ee4798bb3450f6e291bfc88404982636.zip
reverseproxy: do not parse upstream address too early if it contains replaceble parts (#5695)
* reverseproxy: do not parse upstream address too early if it contains replaceble parts * remove unused method * cleanup * accommodate partially replaceable port
Diffstat (limited to 'modules/caddyhttp/reverseproxy/caddyfile.go')
-rw-r--r--modules/caddyhttp/reverseproxy/caddyfile.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go
index 1d86bebd7..f5eb7a5d0 100644
--- a/modules/caddyhttp/reverseproxy/caddyfile.go
+++ b/modules/caddyhttp/reverseproxy/caddyfile.go
@@ -146,7 +146,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// appendUpstream creates an upstream for address and adds
// it to the list.
appendUpstream := func(address string) error {
- dialAddr, scheme, err := parseUpstreamDialAddress(address)
+ pa, err := parseUpstreamDialAddress(address)
if err != nil {
return d.WrapErr(err)
}
@@ -154,21 +154,27 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// the underlying JSON does not yet support different
// transports (protocols or schemes) to each backend,
// so we remember the last one we see and compare them
- if commonScheme != "" && scheme != commonScheme {
+ if commonScheme != "" && pa.scheme != commonScheme {
return d.Errf("for now, all proxy upstreams must use the same scheme (transport protocol); expecting '%s://' but got '%s://'",
- commonScheme, scheme)
+ commonScheme, pa.scheme)
}
- commonScheme = scheme
+ commonScheme = pa.scheme
- parsedAddr, err := caddy.ParseNetworkAddress(dialAddr)
+ // if the port of upstream address contains a placeholder, only wrap it with the `Upstream` struct,
+ // delaying actual resolution of the address until request time.
+ if pa.replaceablePort() {
+ h.Upstreams = append(h.Upstreams, &Upstream{Dial: pa.dialAddr()})
+ return nil
+ }
+ parsedAddr, err := caddy.ParseNetworkAddress(pa.dialAddr())
if err != nil {
return d.WrapErr(err)
}
- if parsedAddr.StartPort == 0 && parsedAddr.EndPort == 0 {
+ if pa.isUnix() || !pa.rangedPort() {
// unix networks don't have ports
h.Upstreams = append(h.Upstreams, &Upstream{
- Dial: dialAddr,
+ Dial: pa.dialAddr(),
})
} else {
// expand a port range into multiple upstreams