optimize: dns delay & fallback
This commit is contained in:
parent
737bec0d2e
commit
4861503f16
7
http.go
7
http.go
@ -55,7 +55,10 @@ var cli = comandyClient(http.Client{
|
||||
if len(addrs) == 0 {
|
||||
addrs, err = resolver.LookupHost(ctx, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
addrs, err = net.DefaultResolver.LookupHost(ctx, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
lookupTable.Set(host, addrs)
|
||||
}
|
||||
@ -80,7 +83,7 @@ var cli = comandyClient(http.Client{
|
||||
}
|
||||
_ = tlsConn.Close()
|
||||
}
|
||||
return tlsConn, nil
|
||||
return tlsConn, err
|
||||
},
|
||||
},
|
||||
})
|
||||
|
10
ipv6.go
10
ipv6.go
@ -1,13 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/RomiChan/syncx"
|
||||
)
|
||||
|
||||
var canUseIPv6 = syncx.Lazy[bool]{Init: func() bool {
|
||||
resp, err := http.Get("http://v6.ipv6-test.com/json/widgetdata.php?callback=?")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
|
||||
defer cancel()
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "http://v6.ipv6-test.com/json/widgetdata.php?callback=?", nil)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user