Class: Rx::Check::HttpCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/rx/check/http_check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, name = "http", timeout: 1) ⇒ HttpCheck

Returns a new instance of HttpCheck.



8
9
10
11
12
# File 'lib/rx/check/http_check.rb', line 8

def initialize(url, name = "http", timeout: 1)
  @url = URI(url)
  @name = name
  @timeout = timeout
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rx/check/http_check.rb', line 6

def name
  @name
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



6
7
8
# File 'lib/rx/check/http_check.rb', line 6

def timeout
  @timeout
end

Instance Method Details

#checkObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/rx/check/http_check.rb', line 14

def check
  Result.from(name) do
    http = Net::HTTP.new(url.host, url.port)
    http.read_timeout = timeout
    http.use_ssl = url.scheme == "https"

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