def ping(host = @host)
      super(host)
      bool = false

      # See https://bugs.ruby-lang.org/issues/8645
      host = "http://#{host}" unless /\A(http(s)?:\/\/)/.match(host)

      uri = URI.parse(host)

      # A port provided here via the host argument overrides anything
      # provided in constructor.
      #
      port = URI.split(host)[3] || URI.parse(host).port || @port
      port = port.to_i

      start_time = Time.now

      response = do_ping(uri, port)

      if response.is_a?(Net::HTTPSuccess)
        bool = true
      elsif redirect?(response) # Check code, HTTPRedirection does not always work
        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'])
            port = redirect.port
            redirect = uri + redirect if redirect.relative?

            start_time = Time.now
            response = do_ping(redirect, port)
            rlimit += 1
          end

          if response.is_a?(Net::HTTPSuccess)
            bool = true
          else
            @warning   = nil
            @exception ||= response.message
          end

        else
          @exception = response.message
        end
      else
        @exception ||= response.message
      end

      # There is no duration if the ping failed
      @duration = Time.now - start_time if bool

      bool
    end
def ping(host = @host)
      super(host)
      bool = false

      # See https://bugs.ruby-lang.org/issues/8645
      host = "http://#{host}" unless /\A(http(s)?:\/\/)/.match(host)

      uri = URI.parse(host)

      # A port provided here via the host argument overrides anything
      # provided in constructor.
      #
      port = URI.split(host)[3] || URI.parse(host).port || @port
      port = port.to_i

      start_time = Time.now

      response = do_ping(uri, port)

      if response.is_a?(Net::HTTPSuccess)
        bool = true
      elsif redirect?(response) # Check code, HTTPRedirection does not always work
        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'])
            port = redirect.port
            redirect = uri + redirect if redirect.relative?

            start_time = Time.now
            response = do_ping(redirect, port)
            rlimit += 1
          end

          if response.is_a?(Net::HTTPSuccess)
            bool = true
          else
            @warning   = nil
            @exception ||= response.message
          end

        else
          @exception = response.message
        end
      else
        @exception ||= response.message
      end

      # There is no duration if the ping failed
      @duration = Time.now - start_time if bool

      bool
    end
Creates and returns a new Ping::HTTP object. The default port is the
 port associated with the URI or 80. The default timeout is 5 seconds.

 Looks for an HTTP response from the URI passed to the constructor.
 If the result is a kind of Net::HTTPSuccess then the ping was
 successful and true is returned.  Otherwise, false is returned
 and the Ping::HTTP#exception method should contain a string
 indicating what went wrong.

 If the HTTP#follow_redirect accessor is set to true (which it is
 by default) and a redirect occurs during the ping, then the
 HTTP#warning attribute is set to the redirect message, but the
 return result is still true. If it's set to false then a redirect
 response is considered a failed ping.

 If no file or path is specified in the URI, then '/' is assumed.
 If no scheme is present in the URI, then 'http' is assumed.