Class: Arachni::HTTP::CookieJar
- Includes:
- Utilities
- Defined in:
- lib/arachni/http/cookie_jar.rb
Overview
Basic CookieJar implementation.
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(cookies) ⇒ CookieJar
self
. - #==(other) ⇒ Object
-
#any? ⇒ Bool
true
if cookiejar is not empty,false
otherwise. -
#clear ⇒ Object
Empties the cookiejar.
-
#cookies(include_expired = false) ⇒ Array<Cookie>
All cookies.
-
#empty? ⇒ Bool
true
if cookiejar is empty,false
otherwise. -
#for_url(url) ⇒ Array<Cookie>
URL which should be sent to the resource at
url
. - #hash ⇒ Object
-
#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.
- #merge!(other) ⇒ Object
-
#update(cookies) ⇒ CookieJar
Updates the jar with
cookies
.
Methods included from Utilities
#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_file, #cookies_from_parser, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_parser, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_parser, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite
Constructor Details
#initialize(cookie_jar_file = nil) ⇒ CookieJar
Returns a new instance of CookieJar.
41 42 43 44 |
# File 'lib/arachni/http/cookie_jar.rb', line 41 def initialize( = nil ) @cookies = {} load( ) if end |
Class Method Details
.from_file(*args) ⇒ Arachni::HTTP::CookieJar
Same as #initialize.
35 36 37 |
# File 'lib/arachni/http/cookie_jar.rb', line 35 def self.from_file( *args ) new.load( *args ) end |
Instance Method Details
#<<(cookies) ⇒ CookieJar
Returns self
.
69 70 71 72 73 74 75 |
# File 'lib/arachni/http/cookie_jar.rb', line 69 def <<( ) [].flatten.each do || next if ! ( ) end self end |
#==(other) ⇒ Object
168 169 170 |
# File 'lib/arachni/http/cookie_jar.rb', line 168 def ==( other ) hash == other.hash end |
#any? ⇒ Bool
Returns true
if cookiejar is not empty, false
otherwise.
163 164 165 |
# File 'lib/arachni/http/cookie_jar.rb', line 163 def any? !empty? end |
#clear ⇒ Object
Empties the cookiejar.
151 152 153 |
# File 'lib/arachni/http/cookie_jar.rb', line 151 def clear @cookies.clear end |
#cookies(include_expired = false) ⇒ Array<Cookie>
Returns All cookies.
138 139 140 141 142 143 |
# File 'lib/arachni/http/cookie_jar.rb', line 138 def ( include_expired = false ) @cookies.values.map do || next if !include_expired && .expired? end.compact end |
#empty? ⇒ Bool
Returns true
if cookiejar is empty, false
otherwise.
157 158 159 |
# File 'lib/arachni/http/cookie_jar.rb', line 157 def empty? @cookies.empty? end |
#for_url(url) ⇒ Array<Cookie>
Returns URL which should be sent to the resource at url
.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/arachni/http/cookie_jar.rb', line 111 def for_url( url ) uri = to_uri( url ) request_path = uri.path request_domain = uri.host return [] if !request_domain || !request_path = {} @cookies.values.map do || if .expired? || !request_path.start_with?( .path ) || !in_domain?( .domain, request_domain ) next end [.name] = end .values.sort do |lhs, rhs| rhs.path.length <=> lhs.path.length end end |
#hash ⇒ Object
172 173 174 |
# File 'lib/arachni/http/cookie_jar.rb', line 172 def hash .map(&:to_s).hash end |
#load(cookie_jar_file, url = '') ⇒ CookieJar
Loads cookies from a Netscape cookiejar file.
54 55 56 57 58 59 60 61 62 |
# File 'lib/arachni/http/cookie_jar.rb', line 54 def load( , url = '' ) if !File.exist?( ) fail Error::CookieJarFileNotFound, "Cookie-jar '#{}' doesn't exist." end update( ( url, ) ) self end |
#merge!(other) ⇒ Object
146 147 148 |
# File 'lib/arachni/http/cookie_jar.rb', line 146 def merge!( other ) update other. end |
#update(cookies) ⇒ CookieJar
Updates the jar with cookies
.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/arachni/http/cookie_jar.rb', line 83 def update( ) [].flatten.each do |c| next if !c self << case c when String Cookie.( ::Arachni::Options.url.to_s, c ) when Hash next if c.empty? if c.size > 1 Cookie.new( { url: ::Arachni::Options.url.to_s }.merge( c ) ) else Cookie.new( url: ::Arachni::Options.url.to_s, inputs: c ) end when Cookie c end end self end |