Skip to content

Commit

Permalink
tweak doh test
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Oct 26, 2024
1 parent e480b4d commit d1442ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,36 @@ package main

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"net/url"
"time"

"github.com/phuslu/fastdns"
)

func main() {
doh := "https://1.1.1.1/dns-query"
server := "1.1.1.1"

client := &fastdns.Client{
Addr: doh,
Addr: server,
Dialer: &fastdns.HTTPDialer{
Endpoint: func() (u *url.URL) { u, _ = url.Parse(doh); return }(),
Endpoint: func() (u *url.URL) { u, _ = url.Parse("https://" + server + "/dns-query"); return }(),
UserAgent: "fastdns/0.9",
Transport: http.DefaultTransport,
Transport: &http.Transport{
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: &tls.Config{
NextProtos: []string{"h2"},
InsecureSkipVerify: false,
ServerName: server,
ClientSessionCache: tls.NewLRUClientSessionCache(1024),
},
ExpectContinueTimeout: 1 * time.Second,
},
},
}

Expand Down
19 changes: 16 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastdns

import (
"context"
"crypto/tls"
"net"
"net/http"
"net/netip"
Expand Down Expand Up @@ -260,14 +261,26 @@ func BenchmarkResolverFastdnsUDPAppend(b *testing.B) {
}

func BenchmarkResolverFastdnsHTTP(b *testing.B) {
server := "8.8.8.8:53"
server := "1.1.1.1"

resolver := &Client{
Addr: server,
Dialer: &HTTPDialer{
Endpoint: func() (u *url.URL) { u, _ = url.Parse("https://1.1.1.1/dns-query"); return }(),
Endpoint: func() (u *url.URL) { u, _ = url.Parse("https://" + server + "/dns-query"); return }(),
UserAgent: "fastdns/0.9",
Transport: http.DefaultTransport,
Transport: &http.Transport{
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: &tls.Config{
NextProtos: []string{"h2"},
InsecureSkipVerify: false,
ServerName: server,
ClientSessionCache: tls.NewLRUClientSessionCache(1024),
},
ExpectContinueTimeout: 1 * time.Second,
},
},
}

Expand Down

0 comments on commit d1442ae

Please sign in to comment.