Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question