Module: Opticon::HTTP

Included in:
Tester::Base
Defined in:
lib/opticon/http.rb

Instance Method Summary collapse

Instance Method Details

#get(get_uri) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/opticon/http.rb', line 19

def get(get_uri)
  if self.uri.kind_of? URI
    get_uri = self.uri
  else
    get_uri = URI.parse(self.uri) unless self.uri.kind_of? URI
  end
  
  @last_fetched_uri = get_uri
  
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == "https"
  
  response = nil

  timeout(Opticon.default_timeout) do
    http.start do
      path = uri.path.empty? ? '/' : uri.path
      response = http.request_get(path)
    end
  end

  response
end

#responseObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/opticon/http.rb', line 8

def response
  raise "URI cannot be empty" if uri.kind_of? String and (uri.nil? or uri.empty?)
  
  self.uri = URI.parse(self.uri) unless self.uri.kind_of? URI
  if @response and self.uri == @last_fetched_uri
    @response
  else 
    @response = get(self.uri)
  end
end