mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
fix: make doh truly singleton
This commit is contained in:
parent
c93ddd67e0
commit
e9de332163
50
dns/doh.go
50
dns/doh.go
@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
@ -20,35 +21,38 @@ type DoHClient struct {
|
||||
}
|
||||
|
||||
var client *DoHClient
|
||||
var clientOnce sync.Once
|
||||
|
||||
func GetDoHClient(upstream string) *DoHClient {
|
||||
if client == nil {
|
||||
if !strings.HasPrefix(upstream, "https://") {
|
||||
upstream = "https://" + upstream
|
||||
}
|
||||
clientOnce.Do(func() {
|
||||
if client == nil {
|
||||
if !strings.HasPrefix(upstream, "https://") {
|
||||
upstream = "https://" + upstream
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(upstream, "/dns-query") {
|
||||
upstream = upstream + "/dns-query"
|
||||
}
|
||||
if !strings.HasSuffix(upstream, "/dns-query") {
|
||||
upstream = upstream + "/dns-query"
|
||||
}
|
||||
|
||||
c := &http.Client{
|
||||
Timeout: 5 * time.Second,
|
||||
Transport: &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 3 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext,
|
||||
TLSHandshakeTimeout: 5 * time.Second,
|
||||
MaxIdleConnsPerHost: 100,
|
||||
MaxIdleConns: 100,
|
||||
},
|
||||
}
|
||||
c := &http.Client{
|
||||
Timeout: 5 * time.Second,
|
||||
Transport: &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 3 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext,
|
||||
TLSHandshakeTimeout: 5 * time.Second,
|
||||
MaxIdleConnsPerHost: 100,
|
||||
MaxIdleConns: 100,
|
||||
},
|
||||
}
|
||||
|
||||
client = &DoHClient{
|
||||
upstream: upstream,
|
||||
c: c,
|
||||
client = &DoHClient{
|
||||
upstream: upstream,
|
||||
c: c,
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return client
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user