Class: Anemone::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/anemone/http.rb

Constant Summary collapse

REDIRECT_LIMIT =

Maximum number of redirects to follow on each get_response

5

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ HTTP

Returns a new instance of HTTP.



9
10
11
12
# File 'lib/anemone/http.rb', line 9

def initialize(opts = {})
  @connections = {}
  @opts = opts
end

Instance Method Details

#fetch_page(url, from_page = nil) ⇒ Object

Create a new Page from the response of an HTTP request to url



17
18
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/anemone/http.rb', line 17

def fetch_page(url, from_page = nil)
  begin
    url = URI(url) unless url.is_a?(URI)

    if from_page
      referer = from_page.url
      depth = from_page.depth + 1
    end

    response, code, location, response_time = get(url, referer)

    aka = nil
    if !url.eql?(location)
      aka = location
    end

    return Page.new(url, response.body.dup, code, response.to_hash, aka, referer, depth, response_time)
  rescue => e
    if verbose?
      puts e.inspect
      puts e.backtrace
    end        
    return Page.new(url)
  end
end