class Addressable::URI

def validate

Ensures that the URI is valid.
#
def validate
  return if !!@validation_deferred
  if self.scheme != nil && self.ip_based? &&
      (self.host == nil || self.host.empty?) &&
      (self.path == nil || self.path.empty?)
    raise InvalidURIError,
      "Absolute URI missing hierarchical segment: '#{self.to_s}'"
  end
  if self.host == nil
    if self.port != nil ||
        self.user != nil ||
        self.password != nil
      raise InvalidURIError, "Hostname not supplied: '#{self.to_s}'"
    end
  end
  if self.path != nil && !self.path.empty? && self.path[0..0] != SLASH &&
      self.authority != nil
    raise InvalidURIError,
      "Cannot have a relative path with an authority set: '#{self.to_s}'"
  end
  if self.path != nil && !self.path.empty? &&
      self.path[0..1] == SLASH + SLASH && self.authority == nil
    raise InvalidURIError,
      "Cannot have a path with two leading slashes " +
      "without an authority set: '#{self.to_s}'"
  end
  unreserved = CharacterClasses::UNRESERVED
  sub_delims = CharacterClasses::SUB_DELIMS
  if !self.host.nil? && (self.host =~ /[<>{}\/\\\?\#\@"[[:space:]]]/ ||
      (self.host[/^\[(.*)\]$/, 1] != nil && self.host[/^\[(.*)\]$/, 1] !~
      Regexp.new("^[#{unreserved}#{sub_delims}:]*$")))
    raise InvalidURIError, "Invalid character in host: '#{self.host.to_s}'"
  end
  return nil
end