class Rack::Healthcheck::Checks::HTTPRequest
Attributes
config[R]
Public Class Methods
new(name, config)
click to toggle source
@param name [String] @param config [Hash<Symbol, Object>] Hash with configs @example name = Ceph or Another system config = {
url: localhost, headers: {"Host" => "something"}, service_type: "INTERNAL_SERVICE", expected_result: "LIVE", optional: true
} @see Rack::Healthcheck::Type
Calls superclass method
Rack::Healthcheck::Checks::Base::new
# File lib/rack/healthcheck/checks/http_request.rb, line 26 def initialize(name, config) raise InvalidURL, "Expected :url to be a http or https endpoint" if config[:url].match(%r{^(http://|https://)}).nil? super(name, config[:service_type], config[:optional], config[:url]) @config = config end
Private Instance Methods
check()
click to toggle source
# File lib/rack/healthcheck/checks/http_request.rb, line 35 def check uri = URI(url) http = Net::HTTP.new(uri.host) response = http.get(uri.path, config[:headers]) @status = response.body.delete("\n") == config[:expected_result] rescue StandardError => _ @status = false end