Skip to main content

resolve_localhost

Function resolve_localhost 

Source
pub fn resolve_localhost(endpoint: &str) -> String
Expand description

If endpoint contains localhost, race IPv4 vs IPv6 TCP connects and return a rewritten URL using the winning literal address. If both fail (or the URL doesn’t use localhost), the original endpoint is returned unchanged.

§Examples

use koi_common::net::resolve_localhost;

// Non-localhost URLs pass through unchanged.
assert_eq!(
    resolve_localhost("http://192.168.1.5:5641"),
    "http://192.168.1.5:5641"
);