Class: Arachni::HTTP::CookieJar
- Includes:
- Utilities
- Defined in:
- lib/arachni/http/cookie_jar.rb
Overview
Basic CookieJar implementation.
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(cookie) ⇒ CookieJar
Updates the jar with
cookie. -
#any? ⇒ Bool
trueif cookiejar is not empty,falseotherwise. -
#clear ⇒ Object
Empties the cookiejar.
-
#cookies(include_expired = false) ⇒ Array<Cookie>
Returns all cookies.
-
#empty? ⇒ Bool
trueif cookiejar is empty,falseotherwise. -
#for_url(url) ⇒ Array<Cookie>
Gets cookies for a specific
url. -
#initialize(cookie_jar_file = nil) ⇒ CookieJar
constructor
A new instance of CookieJar.
-
#load(cookie_jar_file, url = '') ⇒ CookieJar
Loads cookies from a Netscape cookiejar file.
-
#update(cookies) ⇒ CookieJar
Updates the jar with
cookies.
Methods included from Utilities
#cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #extract_domain, #form_decode, #form_encode, #form_parse_request_body, #forms_from_document, #forms_from_response, #get_path, #hash_keys_to_str, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_query, #parse_set_cookie, #parse_url_vars, #path_in_domain?, #path_too_deep?, #remove_constants, #seed, #skip_path?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize
Constructor Details
#initialize(cookie_jar_file = nil) ⇒ CookieJar
Returns a new instance of CookieJar.
38 39 40 41 |
# File 'lib/arachni/http/cookie_jar.rb', line 38 def initialize( = nil ) @domains = {} load( ) if end |
Class Method Details
.from_file(*args) ⇒ Arachni::HTTP::CookieJar
Same as #initialize.
33 34 35 |
# File 'lib/arachni/http/cookie_jar.rb', line 33 def self.from_file( *args ) new.load( *args ) end |
Instance Method Details
#<<(cookie) ⇒ CookieJar
Updates the jar with cookie.
68 69 70 71 |
# File 'lib/arachni/http/cookie_jar.rb', line 68 def <<( ) ((@domains[.domain] ||= {})[.path] ||= {})[.name] = .dup self end |
#any? ⇒ Bool
Returns true if cookiejar is not empty, false otherwise.
142 143 144 |
# File 'lib/arachni/http/cookie_jar.rb', line 142 def any? !empty? end |
#clear ⇒ Object
Empties the cookiejar
132 133 134 |
# File 'lib/arachni/http/cookie_jar.rb', line 132 def clear @domains.clear end |
#cookies(include_expired = false) ⇒ Array<Cookie>
Returns all cookies
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/arachni/http/cookie_jar.rb', line 119 def ( include_expired = false ) @domains.values.map do |paths| paths.values.map do || if !include_expired .values.reject{ |c| c.expired? } else .values end end end.flatten.compact end |
#empty? ⇒ Bool
Returns true if cookiejar is empty, false otherwise.
137 138 139 |
# File 'lib/arachni/http/cookie_jar.rb', line 137 def empty? @domains.empty? end |
#for_url(url) ⇒ Array<Cookie>
Gets cookies for a specific url.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/arachni/http/cookie_jar.rb', line 92 def for_url( url ) uri = to_uri( url ) request_path = uri.path request_domain = uri.host return [] if !request_domain || !request_path @domains.map do |domain, paths| next if !in_domain?( domain, request_domain ) paths.map do |path, | next if !request_path.start_with?( path ) .values.reject{ |c| c.expired? } end end.flatten.compact.sort do |lhs, rhs| rhs.path.length <=> lhs.path.length end end |
#load(cookie_jar_file, url = '') ⇒ CookieJar
Loads cookies from a Netscape cookiejar file
51 52 53 54 55 56 57 58 59 |
# File 'lib/arachni/http/cookie_jar.rb', line 51 def load( , url = '' ) # make sure that the provided cookie-jar file exists if !File.exist?( ) fail( Exceptions::NoCookieJar, 'Cookie-jar \'' + + '\' doesn\'t exist.' ) end update( ( url, ) ) self end |
#update(cookies) ⇒ CookieJar
Updates the jar with cookies.
80 81 82 83 |
# File 'lib/arachni/http/cookie_jar.rb', line 80 def update( ) [].flatten.compact.each { |c| self << c } self end |