T
T
Twindo2015-03-03 20:29:42
go
Twindo, 2015-03-03 20:29:42

Custom DNS Resolver for http.Client perhaps?

Is it possible in Go in http.Client to override DNS Resolver by specifying your local or any other? And if so, how to do it?
For example, in Java (using the apache http client) this is done like this:

DnsResolver dnsResolver = new CustomDnsResolver();
...
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(
socketFactoryRegistry, connFactory, dnsResolver);
...
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
David Mzareulyan, 2015-04-17
@Twindo

I have never done this, but if you already have a resolver code (which gives out IP by name), then there are no special problems ...
As it is written in https://golang.org/pkg/net/http/ , “For control over proxies , TLS configuration, keep-alives, compression, and other settings, create a Transport”.
In your case, you need to create an instance of http.Transport with your own Dial function:
In this function, you get the host in the “addr” parameter, resolve it yourself, and then call the standard net.Dial, but not with the host, but with the resolved IP -address. And then you do http.Client with this transport:
and use it as usual.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question