class Rx::Check::HttpCheck

Attributes

name[R]
url[R]

Public Class Methods

new(url, name = "http") click to toggle source
# File lib/rx/check/http_check.rb, line 8
def initialize(url, name = "http")
  @url = URI(url)
  @name = name
end

Public Instance Methods

check() click to toggle source
# File lib/rx/check/http_check.rb, line 13
def check
  Result.from(name) do
    http = Net::HTTP.new(url.host, url.port)
    http.read_timeout = 1
    http.use_ssl = url.scheme == "https"

    response = http.request(Net::HTTP::Get.new(path))
    response.code == "200"
  end
end

Private Instance Methods

path() click to toggle source
# File lib/rx/check/http_check.rb, line 28
def path
  path = url.path == "" ? "/" : url.path
  path = "#{path}?#{url.query}" if url.query
  path = "#{path}##{url.fragment}" if url.fragment

  path
end