Class: CMSScanner::Browser
- Inherits:
-
Object
- Object
- CMSScanner::Browser
show all
- Extended by:
- Actions
- Defined in:
- lib/cms_scanner/browser.rb,
lib/cms_scanner/browser/actions.rb,
lib/cms_scanner/browser/options.rb
Overview
Options available in the Browser
Defined Under Namespace
Modules: Actions
Constant Summary
collapse
- OPTIONS =
[
:cache_ttl,
:cookie_jar,
:cookie_string,
:connect_timeout,
:http_auth,
:max_threads,
:proxy,
:proxy_auth,
:request_timeout,
:user_agent
]
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Actions
get, get_and_follow_location, head, post
Constructor Details
#initialize(parsed_options = {}) ⇒ Void
12
13
14
|
# File 'lib/cms_scanner/browser.rb', line 12
def initialize(parsed_options = {})
load_options(parsed_options)
end
|
Class Method Details
.instance(parsed_options = {}) ⇒ Browser
21
22
23
|
# File 'lib/cms_scanner/browser.rb', line 21
def self.instance(parsed_options = {})
@@instance ||= new(parsed_options)
end
|
.reset ⇒ Object
25
26
27
|
# File 'lib/cms_scanner/browser.rb', line 25
def self.reset
@@instance = nil
end
|
Instance Method Details
#default_request_params ⇒ Hash
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/cms_scanner/browser.rb', line 38
def default_request_params
params = {
ssl_verifypeer: false, ssl_verifyhost: 2, headers: { 'User-Agent' => user_agent }
}
{ connecttimeout: :connect_timeout, cache_ttl: :cache_ttl,
proxy: :proxy, timeout: :request_timeout, cookiejar: :cookie_jar,
cookiefile: :cookie_jar, cookie: :cookie_string
}.each do |typhoeus_opt, browser_opt|
attr_value = public_send(browser_opt)
params[typhoeus_opt] = attr_value unless attr_value.nil?
end
params[:proxyauth] = "#{proxy_auth[:username]}:#{proxy_auth[:password]}" if proxy_auth
params[:userpwd] = "#{http_auth[:username]}:#{http_auth[:password]}" if http_auth
params
end
|
#forge_request(url, params = {}) ⇒ Typhoeus::Request
33
34
35
|
# File 'lib/cms_scanner/browser.rb', line 33
def forge_request(url, params = {})
Typhoeus::Request.new(url, request_params(params))
end
|
#hydra ⇒ Object
26
27
28
|
# File 'lib/cms_scanner/browser/options.rb', line 26
def hydra
@hydra ||= Typhoeus::Hydra.new(max_concurrency: max_threads || 1)
end
|
#load_options(options = {}) ⇒ Object
20
21
22
23
24
|
# File 'lib/cms_scanner/browser/options.rb', line 20
def load_options(options = {})
OPTIONS.each do |sym|
send("#{sym}=", options[sym]) if options.key?(sym)
end
end
|
#max_threads=(number) ⇒ Object
Set the threads attribute and update the max_concurrency of Typhoeus::Hydra
34
35
36
37
|
# File 'lib/cms_scanner/browser/options.rb', line 34
def max_threads=(number)
@max_threads = number.to_i > 0 ? number.to_i : 1
hydra.max_concurrency = @max_threads
end
|
#request_params(params = {}) ⇒ Hash
62
63
64
65
66
|
# File 'lib/cms_scanner/browser.rb', line 62
def request_params(params = {})
default_request_params.merge(params) do |key, oldval, newval|
key == :headers ? oldval.merge(newval) : newval
end
end
|
#user_agent ⇒ Object
40
41
42
|
# File 'lib/cms_scanner/browser/options.rb', line 40
def user_agent
@user_agent ||= "CMSScanner v#{VERSION}"
end
|