Feature: resolve ip with a proxy adapter

This commit is contained in:
yaling888
2022-02-23 02:38:50 +08:00
parent b192238699
commit d876d6e74c
14 changed files with 357 additions and 101 deletions

View File

@ -19,8 +19,9 @@ const (
)
type dohClient struct {
url string
transport *http.Transport
url string
proxyAdapter string
transport *http.Transport
}
func (dc *dohClient) Exchange(m *D.Msg) (msg *D.Msg, err error) {
@ -79,9 +80,10 @@ func (dc *dohClient) doRequest(req *http.Request) (msg *D.Msg, err error) {
return msg, err
}
func newDoHClient(url string, r *Resolver) *dohClient {
func newDoHClient(url string, r *Resolver, proxyAdapter string) *dohClient {
return &dohClient{
url: url,
url: url,
proxyAdapter: proxyAdapter,
transport: &http.Transport{
ForceAttemptHTTP2: true,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
@ -95,7 +97,11 @@ func newDoHClient(url string, r *Resolver) *dohClient {
return nil, err
}
return dialer.DialContext(ctx, "tcp", net.JoinHostPort(ip.String(), port))
if proxyAdapter == "" {
return dialer.DialContext(ctx, "tcp", net.JoinHostPort(ip.String(), port))
} else {
return dialContextWithProxyAdapter(ctx, proxyAdapter, "tcp", ip, port)
}
},
},
}