reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Initialize without error when `/etc/resolv.conf` is missing

Open roberth opened this issue 2 years ago • 3 comments

Some restricted environments may not have /etc/resolv.conf, to keep things simple and reduce entropy. The latter reason is why Nix doesn't provide one in its (offline) sandbox. By allowing initialization to continue in this circumstance, it is possible for programs that use reqwest to keep their state simple, while allowing to be run in such restricted environments.

The error from the missing file seems to be propagated through here: https://github.com/seanmonstar/reqwest/blob/6792f697fcdb27c47dcbf7bd05f23368d1d4ac80/src/dns/trust_dns.rs#L56

Cases where this is useful include

  • https://github.com/lycheeverse/lychee/issues/1303
  • Nix builds that run tests of Rust programs that use reqwest

roberth avatar Nov 23 '23 11:11 roberth

Would it be acceptable to simply continue with an empty config if the system resolv.conf is missing? Should it print a warning in that case? Or should this behavior by opt-in, configured by the caller somehow? Is the library designed so that the resolver is pluggable?

roberth avatar Jan 29 '24 18:01 roberth

Yes, reqwest allows for custom resolvers

seanmonstar avatar Jan 29 '24 21:01 seanmonstar