ferron_common/util/
is_localhost.rs

1use std::net::IpAddr;
2
3/// Determines if the server configuration filter implies `localhost`.
4pub fn is_localhost(ip: Option<&IpAddr>, hostname: Option<&str>) -> bool {
5  if let Some(ip) = ip {
6    if ip.to_canonical().is_loopback() {
7      return true;
8    }
9  }
10  if let Some(hostname) = hostname {
11    let normalized_hostname = hostname.to_lowercase();
12    let normalized_hostname = normalized_hostname.trim_end_matches('.');
13    if normalized_hostname == "localhost" || normalized_hostname.ends_with(".localhost") {
14      return true;
15    }
16  }
17  false
18}