def ping(host = @host)
super(host)
bool = false
uri = URI.parse(host)
start_time = Time.now
begin
response = nil
uri_path = uri.path.empty? ? '/' : uri.path
headers = { }
headers["User-Agent"] = user_agent unless user_agent.nil?
Timeout.timeout(@timeout) do
Net::HTTP.new(uri.host, @port).start do |http|
response = http.request_get(uri_path, headers)
end
end
rescue Exception => err
@exception = err.message
else
if response.is_a?(Net::HTTPSuccess)
bool = true
else
if @follow_redirect
@warning = response.message
while response.is_a?(Net::HTTPRedirection)
redirect = URI.parse(response['location'])
redirect = uri + redirect if redirect.relative?
response = Net::HTTP.get_response(redirect.host, redirect.path, @port)
end
if response.is_a?(Net::HTTPSuccess)
bool = true
else
@warning = nil
@exception = response.message
end
else
@exception = response.message
end
end
end
@duration = Time.now - start_time if bool
bool
end