Fix host trailing dot in Discover

This commit is contained in:
Simon Ser 2020-01-20 13:17:19 +01:00
parent 19140af10d
commit d21315e9fc
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"strings"
"github.com/emersion/go-vcard" "github.com/emersion/go-vcard"
"github.com/emersion/go-webdav" "github.com/emersion/go-webdav"
@ -30,11 +31,16 @@ func Discover(domain string) (string, error) {
} }
addr := addrs[0] addr := addrs[0]
target := strings.TrimSuffix(addr.Target, ".")
if target == "" {
return "", nil
}
u := url.URL{Scheme: "https"} u := url.URL{Scheme: "https"}
if addr.Port == 443 { if addr.Port == 443 {
u.Host = addr.Target u.Host = addr.Target
} else { } else {
u.Host = fmt.Sprintf("%v:%v", addr.Target, addr.Port) u.Host = fmt.Sprintf("%v:%v", target, addr.Port)
} }
return u.String(), nil return u.String(), nil
} }

View File

@ -1,8 +1,8 @@
package webdav package webdav
import ( import (
"net/http"
"fmt" "fmt"
"net/http"
"github.com/emersion/go-webdav/internal" "github.com/emersion/go-webdav/internal"
) )