Skip to content

Commit 933e96d

Browse files
authored
Allow Doh addresses with ports
1 parent 4db16a2 commit 933e96d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

daze.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ func (c Cdoh) Write(b []byte) (n int, err error) {
157157
// ResolverDoh returns a DoH resolver. For further information, see https://datatracker.ietf.org/doc/html/rfc8484.
158158
func ResolverDoh(addr string) *net.Resolver {
159159
urls := doa.Try(url.Parse(addr))
160-
urls.Host = doa.Try(net.LookupHost(urls.Hostname()))[0]
160+
host := doa.Try(net.LookupHost(urls.Hostname()))[0]
161+
port := urls.Port()
162+
urls.Host = host
163+
if port != "" {
164+
urls.Host = host + ":" + port
165+
}
161166
return &net.Resolver{
162167
PreferGo: true,
163168
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {

daze_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
const (
1313
DazeServerListenOn = "127.0.0.1:28080"
1414
CurlDest = "https://www.zhihu.com"
15+
HostLookup = "google.com"
1516
)
1617

1718
func TestLocaleHTTP(t *testing.T) {
@@ -64,23 +65,23 @@ func TestLocaleSocks5(t *testing.T) {
6465

6566
func TestResolverDns(t *testing.T) {
6667
dns := ResolverDns("1.1.1.1:53")
67-
_, err := dns.LookupHost(context.Background(), "google.com")
68+
_, err := dns.LookupHost(context.Background(), HostLookup)
6869
if err != nil {
6970
t.FailNow()
7071
}
7172
}
7273

7374
func TestResolverDot(t *testing.T) {
7475
dot := ResolverDot("1.1.1.1:853")
75-
_, err := dot.LookupHost(context.Background(), "google.com")
76+
_, err := dot.LookupHost(context.Background(), HostLookup)
7677
if err != nil {
7778
t.FailNow()
7879
}
7980
}
8081

8182
func TestResolverDoh(t *testing.T) {
8283
doh := ResolverDoh("https://1.1.1.1/dns-query")
83-
_, err := doh.LookupHost(context.Background(), "google.com")
84+
_, err := doh.LookupHost(context.Background(), HostLookup)
8485
if err != nil {
8586
t.FailNow()
8687
}

0 commit comments

Comments
 (0)