reqwest
reqwest copied to clipboard
Custom DNS resolver
It would be useful to have a hook into reqwest's DNS resolution.
Sean suggested an interface like this:
Add ClientBuilder::dns_resolver(resolver)
which takes something like
trait Resolve {
type Future: Future<Output = Result<Self::Addrs, Self::Error>>;
type Addrs: Iterator<Item = SocketAddr>;
type Error: Into<Box<dyn std::error::Error + Send + Sync>>;
fn resolve(&self, name: String) -> Self::Future;
}
We could include a resolver_fn
helper perhaps, so resolver_fn(|name| async move { Ok(iter::once(some_addr)) })
could work.
Maybe explicitly a tower_service::Service
?
So I've been thinking about a couple of issues in regards to the API for DNS as it relates to queries. There are situations, like happy eyeballs where multiple queries and multiple responses may be issued in order to say do parallel queries for A
and AAAA
records at the same time. It would be nice if instead of a Future
we allowed for a Stream
as the type returned from resolve
.
Thoughts?
As a "reqwest user", I think it is very useful to customize the dns resolver.
In my case, what I actually need is:
- Specify dns server by ip address (v4/v6)
- Add some cache for already resolved domain name and ip pair, just like "CURLOPT_RESOLVE"
Hope my use case could help on APIs' definition.
Currently, the resolver only runs if the URL does not already contain an IP address. This means, even when providing a custom resolver, one cannot use this to prevent connecting to certain addresses. For example, I would want to prevent certain requests from connecting to internal networks.
This logic is currently hard-wired into the hyper client. @seanmonstar, is this something you would address with this API or would this be a separate concern?
This is very important, I wrote a service for about 7 days, but as a result it turned out to be useless, since the resolver used by default cannot find the domain.
expecting the feature of custom DNS resolver
I think #1386 same as post starter's idea. Dynamic overrides in application.
@seanmonstar I'm having the same problem - I would like to customize DNS resolution but I have no interface to do it with current ClientBuilder.
Currently the resolver is configured in the build()
method of ClientBuilder
. I would like to propose a method to provide my own HttpConnector
to the ClientBuilder
. In that case I could implement my own HttpConnector that contains wrapped Gai or TrustDns resolver and adds custom behaviours I need.
Would you accept a PR for that?
#1441
When time publish this feature?