summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-05-04 14:40:39 -0400
committerGitHub <noreply@github.com>2022-05-04 12:40:39 -0600
commite7fbee8c82740bd3e21c9abdcfe5a1e922244c09 (patch)
tree94b0e68479ce026fef8565829ddb50dcf0e3ba65 /modules/caddyhttp
parente84e19a04eefccc743f0d397efe49ff42626f4b3 (diff)
reverseproxy: Permit resolver addresses to not specify a port (#4760)
Context: https://caddy.community/t/caddy-2-5-dynamic-upstreams-and-consul-srv-dns/15839 I realized it probably makes sense to allow `:53` to be omitted, since it's the default port for DNS.
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/reverseproxy/upstreams.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/upstreams.go b/modules/caddyhttp/reverseproxy/upstreams.go
index 3b58b8d..f788dad 100644
--- a/modules/caddyhttp/reverseproxy/upstreams.go
+++ b/modules/caddyhttp/reverseproxy/upstreams.go
@@ -7,6 +7,7 @@ import (
"net"
"net/http"
"strconv"
+ "strings"
"sync"
"time"
@@ -372,7 +373,14 @@ func (u *UpstreamResolver) ParseAddresses() error {
for _, v := range u.Addresses {
addr, err := caddy.ParseNetworkAddress(v)
if err != nil {
- return err
+ // If a port wasn't specified for the resolver,
+ // try defaulting to 53 and parse again
+ if strings.Contains(err.Error(), "missing port in address") {
+ addr, err = caddy.ParseNetworkAddress(v + ":53")
+ }
+ if err != nil {
+ return err
+ }
}
if addr.PortRangeSize() != 1 {
return fmt.Errorf("resolver address must have exactly one address; cannot call %v", addr)