Skip to content

Commit

Permalink
Improve TXT record parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeukert committed Oct 13, 2020
1 parent 96034fb commit 05682b6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Discover(service string, host string) (string, error) {
if len(addrs) > 0 {
srvTarget := strings.TrimSuffix(addrs[0].Target, ".")

// If we found one, check for TXT records specifying the path
// If we found one, check for a TXT record specifying the path
if srvTarget != "" {
txtRecs, err := net.LookupTXT(fmt.Sprintf("_%vs._tcp.%v", service, host))
if dnsErr, ok := err.(*net.DNSError); ok {
Expand All @@ -49,10 +49,11 @@ func Discover(service string, host string) (string, error) {
}

for _, txtRec := range txtRecs {
// This is not correct according to RFC 6763, but LookupTXT merges all constituent strings together
// This is not correct according to RFC 6763 sections 6.3 to 6.5,
// but LookupTXT merges all constituent strings together
for _, txtRecKeyVal := range strings.Split(txtRec, " ") {
if strings.HasPrefix(txtRecKeyVal, "path=") {
path = strings.TrimPrefix(txtRecKeyVal, "path=")
if strings.HasPrefix(strings.ToLower(txtRecKeyVal), "path=") {
path = txtRecKeyVal[5:]
break
}
}
Expand Down

0 comments on commit 05682b6

Please sign in to comment.