@marcel91200 / caddy Mirror · read-only / commits / e7fbee8c
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 18:00 UTC

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.

Francis Lavoie committed May 4, 2022 at 14:40 UTC e7fbee8c82740bd3e21c9abdcfe5a1e922244c09
1 file changed +9 -1
modules/caddyhttp/reverseproxy/upstreams.go
+9 -1
@@ -7,6 +7,7 @@ import (
7 "net"
8 "net/http"
9 "strconv"
10 + "strings"
11 "sync"
12 "time"
13
@@ -372,7 +373,14 @@ func (u *UpstreamResolver) ParseAddresses() error {
373 for _, v := range u.Addresses {
374 addr, err := caddy.ParseNetworkAddress(v)
375 if err != nil {
375 - return err
376 + // If a port wasn't specified for the resolver,
377 + // try defaulting to 53 and parse again
378 + if strings.Contains(err.Error(), "missing port in address") {
379 + addr, err = caddy.ParseNetworkAddress(v + ":53")
380 + }
381 + if err != nil {
382 + return err
383 + }
384 }
385 if addr.PortRangeSize() != 1 {
386 return fmt.Errorf("resolver address must have exactly one address; cannot call %v", addr)