6 class HttpResponseCode < PollCondition
7 attr_accessor :code_is, :code_is_not, :times, :host, :port, :timeout, :path
15 self.code_is = Array(self.code) if self.code_is
16 self.code_is_not = Array(self.code_is_not) if self.code_is_not
18 if self.times.kind_of?(Integer)
19 self.times = [self.times, self.times]
22 @timeline = Timeline.new(self.times[1])
27 valid &= complain("Attribute 'host' must be specified", self) if self.host.nil?
28 valid &= complain("Attribute 'port' must be specified", self) if self.port.nil?
29 valid &= complain("Attribute 'path' must be specified", self) if self.path.nil?
30 valid &= complain("One (and only one) of attributes 'code_is' and 'code_is_not' must be specified", self) if
31 (self.code_is.nil? && self.code_is_not.nil?) || (self.code_is && self.code_is_not)
32 valid &= complain("Attribute 'timeout' must be specified", self) if self.timeout.nil?
39 Net::HTTP.start(self.host, self.port) do |http|
40 http.read_timeout = self.timeout
41 response = http.head(self.path)
44 if self.code_is && self.code_is.include?(response.code)
46 elsif self.code_is_not && !self.code.include?(response.code)
52 self.code_is ? false : pass