mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-24 02:02:26 -04:00
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.
This commit is contained in:
parent
e84e19a04e
commit
e7fbee8c82
@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -372,7 +373,14 @@ func (u *UpstreamResolver) ParseAddresses() error {
|
|||||||
for _, v := range u.Addresses {
|
for _, v := range u.Addresses {
|
||||||
addr, err := caddy.ParseNetworkAddress(v)
|
addr, err := caddy.ParseNetworkAddress(v)
|
||||||
if err != nil {
|
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 {
|
if addr.PortRangeSize() != 1 {
|
||||||
return fmt.Errorf("resolver address must have exactly one address; cannot call %v", addr)
|
return fmt.Errorf("resolver address must have exactly one address; cannot call %v", addr)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user