Skip to main content

normalize_domain

Function normalize_domain 

Source
pub fn normalize_domain(input: &str) -> ProxyResult<String>
Expand description

The canonical form of a domain name, or why it cannot be one.

Lowercased, with one trailing dot removed, and then held to the LDH rule (letters, digits, hyphen) that every name a certificate authority will issue for, and every name a Host header can carry unencoded, obeys:

  • ASCII only. An internationalised name has to arrive in its punycode (xn--) form. Accepting Unicode would mean picking one of several incompatible normalisations, and two tenants could then register names that render alike and compare different.
  • at least two labels. A single label resolves through the resolver’s search list, which makes it a name for something inside the network, not on it.
  • each label 1 to 63 characters, not starting or ending with a hyphen; the whole at most 253.
  • not an IP address, in any spelling a resolver will accept. 127.1 and 0x7f.1 are IPv4 to inet_aton, so a name whose last label is numeric (or 0x hex) is refused: no real top-level domain is.

Every place a domain enters the system goes through this, so the stored form is the compared form.