Class: Anemone::HTTP

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

Constant Summary

REDIRECT_LIMIT =

Maximum number of redirects to follow on each get_response

5

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (HTTP) initialize(opts = {})



13
14
15
16
17
# File 'lib/anemone/http.rb', line 13

def initialize(opts = {})
  @connections = {}
  @opts = opts
  @cookie_store = CookieStore.new(@opts[:cookies])
end

Instance Attribute Details

CookieStore for this HTTP client



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

def cookie_store
  @cookie_store
end

Instance Method Details

- (Boolean) accept_cookies?

Does this HTTP client accept cookies from the server?



73
74
75
# File 'lib/anemone/http.rb', line 73

def accept_cookies?
  @opts[:accept_cookies]
end

- (Object) fetch_page(url, referer = nil, depth = nil)

Fetch a single Page from the response of an HTTP request to url. Just gets the final destination page.



23
24
25
# File 'lib/anemone/http.rb', line 23

def fetch_page(url, referer = nil, depth = nil)
  fetch_pages(url, referer, depth).last
end

- (Object) fetch_pages(url, referer = nil, depth = nil)

Create new Pages from the response of an HTTP request to url, including redirects



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/anemone/http.rb', line 31

def fetch_pages(url, referer = nil, depth = nil)
  begin
    url = URI(url) unless url.is_a?(URI)
    pages = []
    get(url, referer) do |response, code, location, redirect_to, response_time|
      pages << Page.new(location, :body => response.body.dup,
                                  :code => code,
                                  :headers => response.to_hash,
                                  :referer => referer,
                                  :depth => depth,
                                  :redirect_to => redirect_to,
                                  :response_time => response_time)
    end

    return pages
  rescue Exception => e
    if verbose?
      puts e.inspect
      puts e.backtrace
    end
    return [Page.new(url, :error => e)]
  end
end

- (Object) proxy_host

The proxy address string



80
81
82
# File 'lib/anemone/http.rb', line 80

def proxy_host
  @opts[:proxy_host]
end

- (Object) proxy_port

The proxy port



87
88
89
# File 'lib/anemone/http.rb', line 87

def proxy_port
  @opts[:proxy_port]
end

- (Object) read_timeout

HTTP read timeout in seconds



94
95
96
# File 'lib/anemone/http.rb', line 94

def read_timeout
  @opts[:read_timeout]
end

- (Object) redirect_limit

The maximum number of redirects to follow



58
59
60
# File 'lib/anemone/http.rb', line 58

def redirect_limit
  @opts[:redirect_limit] || REDIRECT_LIMIT
end

- (Object) user_agent

The user-agent string which will be sent with each request, or nil if no such option is set



66
67
68
# File 'lib/anemone/http.rb', line 66

def user_agent
  @opts[:user_agent]
end