Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion daze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions daze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -64,23 +65,23 @@ 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()
}
}

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()
}
}

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()
}
Expand Down