class Addressable::URI

def normalized_host

Returns:
  • (String) - The host component, normalized.
def normalized_host
  return nil unless self.host
  @normalized_host ||= begin
    if !self.host.strip.empty?
      result = ::Addressable::IDNA.to_ascii(
        URI.unencode_component(self.host.strip.downcase)
      )
      if result =~ /[^\.]\.$/
        # Single trailing dots are unnecessary.
        result = result[0...-1]
      end
      result = Addressable::URI.normalize_component(
        result,
        NormalizeCharacterClasses::HOST
      )
      result
    else
      EMPTY_STR.dup
    end
  end
  # All normalized values should be UTF-8
  force_utf8_encoding_if_needed(@normalized_host)
  @normalized_host
end