I am trying to get DNS requests to tunnel through my company's proxy by using the HTTP CONNECT method.
The library I am using to make the DNS requests supports setting a custom net.Dialer
on an instance of dns.Client
. I found another library that claims to act as a drop-in replacement for net.Dialer
that supports initiating TCP connections through a proxy using the HTTP CONNECT method.
However, I can't figure out how to get this to work with these two libraries.
I have tried setting the Dialer
field of dns.Client
, but it complains about incompatible types:
client := &dns.Client{
Net: "tcp",
Timeout: time.Duration(forwarder.Timeout) * time.Second,
}
if forwarder.Proxy != nil {
client.Dialer = http_dialer.New(forwarder.Proxy, http_dialer.WithDialer(client.Dialer))
}
Yields:
cannot use http_dialer.New(forwarder.Proxy, http_dialer.WithDialer(client.Dialer)) (type *http_dialer.HttpTunnel) as type *net.Dialer in assignment
So I tried casting it:
client := &dns.Client{
Net: "tcp",
Timeout: time.Duration(forwarder.Timeout) * time.Second,
}
if forwarder.Proxy != nil {
client.Dialer = net.Dialer(*http_dialer.New(forwarder.Proxy, http_dialer.WithDialer(client.Dialer)))
}
But that yields:
cannot convert *http_dialer.New(forwarder.Proxy, http_dialer.WithDialer(client.Dialer)) (type http_dialer.HttpTunnel) to type net.Dialer
Finally, I tried setting the Dial
function of dns.Client.Dialer
to the Dial
function in the http_dialer.HttpTunnel
returned by http_dialer#New
:
client := &dns.Client{
Net: "tcp",
Timeout: time.Duration(forwarder.Timeout) * time.Second,
}
if forwarder.Proxy != nil {
client.Dialer.Dial = http_dialer.New(forwarder.Proxy, http_dialer.WithDialer(client.Dialer)).Dial
}
But that yielded:
cannot assign to client.Dialer.Dial
So I how do I set the Dialer
of my DNS client?