diff --git a/daze.go b/daze.go index 92cf304..3616cc0 100644 --- a/daze.go +++ b/daze.go @@ -157,7 +157,12 @@ func (c Cdoh) Write(b []byte) (n int, err error) { // ResolverDoh returns a DoH resolver. For further information, see https://datatracker.ietf.org/doc/html/rfc8484. func ResolverDoh(addr string) *net.Resolver { urls := doa.Try(url.Parse(addr)) - urls.Host = doa.Try(net.LookupHost(urls.Hostname()))[0] + host := doa.Try(net.LookupHost(urls.Hostname()))[0] + port := urls.Port() + urls.Host = host + if port != "" { + urls.Host = host + ":" + port + } return &net.Resolver{ PreferGo: true, Dial: func(ctx context.Context, network, address string) (net.Conn, error) { diff --git a/daze_test.go b/daze_test.go index f3af043..19403af 100644 --- a/daze_test.go +++ b/daze_test.go @@ -12,6 +12,7 @@ import ( const ( DazeServerListenOn = "127.0.0.1:28080" CurlDest = "https://www.zhihu.com" + HostLookup = "google.com" ) func TestLocaleHTTP(t *testing.T) { @@ -64,7 +65,7 @@ func TestLocaleSocks5(t *testing.T) { func TestResolverDns(t *testing.T) { dns := ResolverDns("1.1.1.1:53") - _, err := dns.LookupHost(context.Background(), "google.com") + _, err := dns.LookupHost(context.Background(), HostLookup) if err != nil { t.FailNow() } @@ -72,7 +73,7 @@ func TestResolverDns(t *testing.T) { func TestResolverDot(t *testing.T) { dot := ResolverDot("1.1.1.1:853") - _, err := dot.LookupHost(context.Background(), "google.com") + _, err := dot.LookupHost(context.Background(), HostLookup) if err != nil { t.FailNow() } @@ -80,7 +81,7 @@ func TestResolverDot(t *testing.T) { func TestResolverDoh(t *testing.T) { doh := ResolverDoh("https://1.1.1.1/dns-query") - _, err := doh.LookupHost(context.Background(), "google.com") + _, err := doh.LookupHost(context.Background(), HostLookup) if err != nil { t.FailNow() }