Class: WebAgent::Cookie
- Inherits:
-
Object
- Object
- WebAgent::Cookie
- Includes:
- ParseDate, CookieUtils
- Defined in:
- lib/reap/vendor/http-access2/cookie.rb
Constant Summary collapse
- USE =
1
- SECURE =
2
- DOMAIN =
4
- PATH =
8
- DISCARD =
16
- OVERRIDE =
32
- OVERRIDE_OK =
32
Instance Attribute Summary collapse
-
#discard ⇒ Object
writeonly
Sets the attribute discard.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#domain_orig ⇒ Object
writeonly
Sets the attribute domain_orig.
-
#expires ⇒ Object
for Netscape Cookie.
-
#name ⇒ Object
Returns the value of attribute name.
-
#override ⇒ Object
writeonly
Sets the attribute override.
-
#path ⇒ Object
Returns the value of attribute path.
-
#path_orig ⇒ Object
writeonly
Sets the attribute path_orig.
-
#secure ⇒ Object
writeonly
Sets the attribute secure.
-
#url ⇒ Object
Returns the value of attribute url.
-
#use ⇒ Object
writeonly
Sets the attribute use.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #discard? ⇒ Boolean
- #domain_orig? ⇒ Boolean
- #flag ⇒ Object
-
#initialize ⇒ Cookie
constructor
A new instance of Cookie.
- #join_quotedstr(array, sep) ⇒ Object
- #match?(url) ⇒ Boolean
- #override? ⇒ Boolean
- #parse(str, url) ⇒ Object
- #path_orig? ⇒ Boolean
- #secure? ⇒ Boolean
- #set_flag(flag) ⇒ Object
- #use? ⇒ Boolean
Methods included from CookieUtils
#domain_match, #head_match?, #tail_match?, #total_dot_num
Constructor Details
#initialize ⇒ Cookie
Returns a new instance of Cookie.
71 72 73 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 71 def initialize() @discard = @use = @secure = @domain_orig = @path_orig = @override = nil end |
Instance Attribute Details
#discard=(value) ⇒ Object (writeonly)
Sets the attribute discard
61 62 63 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 61 def discard=(value) @discard = value end |
#domain ⇒ Object
Returns the value of attribute domain.
58 59 60 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 58 def domain @domain end |
#domain_orig=(value) ⇒ Object (writeonly)
Sets the attribute domain_orig
61 62 63 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 61 def domain_orig=(value) @domain_orig = value end |
#expires ⇒ Object
for Netscape Cookie
59 60 61 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 59 def expires @expires end |
#name ⇒ Object
Returns the value of attribute name.
57 58 59 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 57 def name @name end |
#override=(value) ⇒ Object (writeonly)
Sets the attribute override
61 62 63 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 61 def override=(value) @override = value end |
#path ⇒ Object
Returns the value of attribute path.
58 59 60 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 58 def path @path end |
#path_orig=(value) ⇒ Object (writeonly)
Sets the attribute path_orig
61 62 63 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 61 def path_orig=(value) @path_orig = value end |
#secure=(value) ⇒ Object (writeonly)
Sets the attribute secure
61 62 63 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 61 def secure=(value) @secure = value end |
#url ⇒ Object
Returns the value of attribute url.
60 61 62 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 60 def url @url end |
#use=(value) ⇒ Object (writeonly)
Sets the attribute use
61 62 63 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 61 def use=(value) @use = value end |
#value ⇒ Object
Returns the value of attribute value.
57 58 59 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 57 def value @value end |
Instance Method Details
#discard? ⇒ Boolean
75 76 77 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 75 def discard? @discard end |
#domain_orig? ⇒ Boolean
87 88 89 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 87 def domain_orig? @domain_orig end |
#flag ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 99 def flag flg = 0 flg += USE if @use flg += SECURE if @secure flg += DOMAIN if @domain_orig flg += PATH if @path_orig flg += DISCARD if @discard flg += OVERRIDE if @override flg end |
#join_quotedstr(array, sep) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 132 def join_quotedstr(array, sep) ret = Array.new() old_elem = nil array.each{|elem| if (elem.scan(/"/).length % 2) == 0 if old_elem old_elem << sep << elem else ret << elem old_elem = nil end else if old_elem old_elem << sep << elem ret << old_elem old_elem = nil else old_elem = elem.dup end end } ret end |
#match?(url) ⇒ Boolean
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 120 def match?(url) domainname = url.host if (!domainname || !domain_match(domainname, @domain) || (@path && !head_match?(@path, url.path)) || (@secure && (url.scheme != 'https')) ) return false else return true end end |
#override? ⇒ Boolean
95 96 97 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 95 def override? @override end |
#parse(str, url) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 156 def parse(str, url) @url = url = str.split(/;/) = join_quotedstr(, ';') first_elem = .shift if first_elem !~ /([^=]*)(\=(.*))?/ return ## raise ArgumentError 'invalid cookie value' end @name = $1.strip @value = $3 if @value if @value =~ /^\s*"(.*)"\s*$/ @value = $1 else @value.dup.strip! end end .each{|pair| key, value = pair.split(/=/) ## value may nil key.strip! if value value = value.strip.sub(/\A"(.*)"\z/) { $1 } end case key.downcase when 'domain' @domain = value when 'expires' begin @expires = Time.gm(*parsedate(value)[0,6]) rescue ArgumentError @expires = nil end when 'path' @path = value when 'secure' @secure = true ## value may nil, but must 'true'. else ## ignore end } end |
#path_orig? ⇒ Boolean
91 92 93 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 91 def path_orig? @path_orig end |
#secure? ⇒ Boolean
83 84 85 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 83 def secure? @secure end |
#set_flag(flag) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 110 def set_flag(flag) flag = flag.to_i @use = true if flag & USE > 0 @secure = true if flag & SECURE > 0 @domain_orig = true if flag & DOMAIN > 0 @path_orig = true if flag & PATH > 0 @discard = true if flag & DISCARD > 0 @override = true if flag & OVERRIDE > 0 end |
#use? ⇒ Boolean
79 80 81 |
# File 'lib/reap/vendor/http-access2/cookie.rb', line 79 def use? @use end |