Class: Anemone::HTTP

Inherits:
Object show all
Includes:
Arachni::UI::Output
Defined in:
lib/anemone/http.rb

Constant Summary collapse

REDIRECT_LIMIT =

Maximum number of redirects to follow on each get_response

5

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Arachni::UI::Output

#buffer, #debug!, #debug?, #flush_buffer, #mute!, #muted?, #only_positives!, #only_positives?, #print_debug, #print_debug_backtrace, #print_debug_pp, #print_error, #print_error_backtrace, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #reroute_to_file, #reroute_to_file?, #unmute!, #verbose!

Constructor Details

#initialize(opts = {}) ⇒ HTTP

Returns a new instance of HTTP.



37
38
39
40
41
# File 'lib/anemone/http.rb', line 37

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

Instance Attribute Details

CookieStore for this HTTP client



35
36
37
# File 'lib/anemone/http.rb', line 35

def cookie_store
  @cookie_store
end

Instance Method Details

#accept_cookies?Boolean

Does this HTTP client accept cookies from the server?

Returns:

  • (Boolean)


97
98
99
# File 'lib/anemone/http.rb', line 97

def accept_cookies?
  @opts[:accept_cookies]
end

#fetch_page(url, referer = nil, depth = nil) ⇒ Object

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



47
48
49
# File 'lib/anemone/http.rb', line 47

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

#fetch_pages(url, referer = nil, depth = nil) ⇒ Object

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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/anemone/http.rb', line 55

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.headers_hash,
                                  :referer => referer,
                                  :depth => depth,
                                  :redirect_to => redirect_to,
                                  :response_time => response_time)
    end

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

#redirect_limitObject

The maximum number of redirects to follow



82
83
84
# File 'lib/anemone/http.rb', line 82

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

#user_agentObject

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



90
91
92
# File 'lib/anemone/http.rb', line 90

def user_agent
  @opts[:user_agent]
end