Skip to content

Commit

Permalink
fix(doh): problems with not recreating a new one when the client is n…
Browse files Browse the repository at this point in the history
…ot valid
  • Loading branch information
EkkoG committed Oct 31, 2024
1 parent 60d45a3 commit 54185ee
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions control/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,32 @@ type DoH struct {

func (d *DoH) ForwardDNS(ctx context.Context, data []byte) (*dnsmessage.Msg, error) {
if d.client == nil {
var roundTripper http.RoundTripper
if d.http3 {
roundTripper = d.getHttp3RoundTripper()
} else {
roundTripper = d.getHttpRoundTripper()
d.client = d.getClient()
}
msg, err := sendHttpDNS(d.client, d.dialArgument.bestTarget.String(), &d.Upstream, data)
if err != nil {
// If failed to send DNS request, we should try to create a new client.
d.client = d.getClient()
msg, err = sendHttpDNS(d.client, d.dialArgument.bestTarget.String(), &d.Upstream, data)
if err != nil {
return nil, err
}
return msg, nil
}
return msg, nil
}

d.client = &http.Client{
Transport: roundTripper,
}
func (d *DoH) getClient() *http.Client {
var roundTripper http.RoundTripper
if d.http3 {
roundTripper = d.getHttp3RoundTripper()
} else {
roundTripper = d.getHttpRoundTripper()
}

return &http.Client{
Transport: roundTripper,
}
return sendHttpDNS(d.client, d.dialArgument.bestTarget.String(), &d.Upstream, data)
}

func (d *DoH) getHttpRoundTripper() *http.Transport {
Expand Down

0 comments on commit 54185ee

Please sign in to comment.