def ping(host = @host)
super(host)
bool = false
host = "http://#{host}" unless host.include?("http")
uri = URI.parse(host)
start_time = Time.now
response = do_ping(uri)
if response.is_a?(Net::HTTPSuccess)
bool = true
elsif redirect?(response)
if @follow_redirect
@warning = response.message
rlimit = 0
while redirect?(response)
if rlimit >= redirect_limit
@exception = "Redirect limit exceeded"
break
end
redirect = URI.parse(response['location'])
redirect = uri + redirect if redirect.relative?
response = do_ping(redirect)
rlimit += 1
end
if response.is_a?(Net::HTTPSuccess)
bool = true
else
@warning = nil
@exception ||= response.message
end
else
@exception = response.message
end
end
@duration = Time.now - start_time if bool
bool
end