diff options
Diffstat (limited to 'middleware/normalize.go')
-rw-r--r-- | middleware/normalize.go | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/middleware/normalize.go b/middleware/normalize.go index 87f3ce703..77ef97993 100644 --- a/middleware/normalize.go +++ b/middleware/normalize.go @@ -7,6 +7,8 @@ import ( "github.com/miekg/dns" ) +// See core/dnsserver/address.go - we should unify these two impls. + // Zones respresents a lists of zone names. type Zones []string @@ -56,12 +58,24 @@ type ( ) // Normalize will return the host portion of host, stripping -// of any port. The host will also be fully qualified and lowercased. +// of any port or transport. The host will also be fully qualified and lowercased. func (h Host) Normalize() string { + + s := string(h) + + switch { + case strings.HasPrefix(s, TransportTLS+"://"): + s = s[len(TransportTLS+"://"):] + case strings.HasPrefix(s, TransportDNS+"://"): + s = s[len(TransportDNS+"://"):] + case strings.HasPrefix(s, TransportGRPC+"://"): + s = s[len(TransportGRPC+"://"):] + } + // separate host and port - host, _, err := net.SplitHostPort(string(h)) + host, _, err := net.SplitHostPort(s) if err != nil { - host, _, _ = net.SplitHostPort(string(h) + ":") + host, _, _ = net.SplitHostPort(s + ":") } return Name(host).Normalize() } @@ -77,3 +91,10 @@ func (a Addr) Normalize() string { // TODO(miek): lowercase it? return net.JoinHostPort(addr, port) } + +// Duplicated from core/dnsserver/address.go ! +const ( + TransportDNS = "dns" + TransportTLS = "tls" + TransportGRPC = "grpc" +) |