reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Custom DNS resolver

Open ry opened this issue 4 years ago • 9 comments

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.

ry avatar Dec 26 '20 13:12 ry

Maybe explicitly a tower_service::Service?

djc avatar Dec 29 '20 21:12 djc

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?

bluejekyll avatar Dec 30 '20 00:12 bluejekyll

As a "reqwest user", I think it is very useful to customize the dns resolver.

In my case, what I actually need is:

  1. Specify dns server by ip address (v4/v6)
  2. Add some cache for already resolved domain name and ip pair, just like "CURLOPT_RESOLVE"

Hope my use case could help on APIs' definition.

CliffHan avatar Jan 11 '21 08:01 CliffHan

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?

jan-auer avatar Jan 11 '21 18:01 jan-auer

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.

PFAhard avatar Feb 03 '21 16:02 PFAhard

expecting the feature of custom DNS resolver

SSebo avatar Jul 21 '21 08:07 SSebo

I think #1386 same as post starter's idea. Dynamic overrides in application.

niuhuan avatar Nov 23 '21 05:11 niuhuan

@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?

rawicki avatar Dec 09 '21 04:12 rawicki

#1441

niuhuan avatar Jan 14 '22 07:01 niuhuan

When time publish this feature?

niuhuan avatar Nov 15 '22 06:11 niuhuan