Class: Bluepill::ProcessConditions::Http
- Inherits:
-
ProcessCondition
- Object
- ProcessCondition
- Bluepill::ProcessConditions::Http
- Defined in:
- lib/bluepill/process_conditions/http.rb
Instance Method Summary collapse
- #check(value) ⇒ Object
-
#initialize(options = {}) ⇒ Http
constructor
A new instance of Http.
- #run(_pid, _include_children) ⇒ Object
Methods inherited from ProcessCondition
Constructor Details
#initialize(options = {}) ⇒ Http
Returns a new instance of Http.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bluepill/process_conditions/http.rb', line 7 def initialize( = {}) @uri = URI.parse([:url]) @kind = begin case [:kind] when Fixnum Net::HTTPResponse::CODE_TO_OBJ[[:kind].to_s] when String, Symbol Net.const_get("HTTP#{[:kind].to_s.camelize}") else Net::HTTPSuccess end end @pattern = [:pattern] || nil @open_timeout = ([:open_timeout] || [:timeout] || 5).to_i @read_timeout = ([:read_timeout] || [:timeout] || 5).to_i end |
Instance Method Details
#check(value) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/bluepill/process_conditions/http.rb', line 42 def check(value) return false unless value.is_a?(@kind) return true unless @pattern return false unless value.class.body_permitted? @pattern =~ value.body end |
#run(_pid, _include_children) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bluepill/process_conditions/http.rb', line 24 def run(_pid, _include_children) session = Net::HTTP.new(@uri.host, @uri.port) if @uri.scheme == 'https' require 'net/https' session.use_ssl = true session.verify_mode = OpenSSL::SSL::VERIFY_NONE end session.open_timeout = @open_timeout session.read_timeout = @read_timeout hide_net_http_bug do session.start do |http| http.get(@uri.request_uri) end end rescue $ERROR_INFO end |