algesten / ureq

A simple, safe HTTP client
Apache License 2.0
1.67k stars 173 forks source link

ureq 3.x improve resolver #784

Closed algesten closed 1 month ago

algesten commented 1 month ago

This is the current Resolver trait.

pub trait Resolver: Debug + Send + Sync + 'static {
    fn resolve(
        &self,
        uri: &Uri,
        config: &AgentConfig,
        timeout: NextTimeout,
    ) -> Result<SocketAddr, Error>;
}

The biggest problem is to only return a single SocketAddr. In testing ureq 3.x I'm trying to use an nginx server bound to localhost:8080, and it turns out the server is only listening to IPv4. However macOS resolves localhost primarily to IPv6. It seems overly simplistic to return a single address. We need to return "a number" of addresses that can be attempted in turn and check for the Io(Os { code: 61, kind: ConnectionRefused, message: "Connection refused" }) error to try the next.

algesten commented 1 month ago

smallvec is already a dep (via hoot), I suggest we use a fixed number of address slots as return type via SmallVec. Something like 10-16 would be enough.