class WebAgent::Cookie
Constants
- DISCARD
- DOMAIN
- HTTP_ONLY
- OVERRIDE
- OVERRIDE_OK
- PATH
- SECURE
- USE
Attributes
discard[W]
domain[RW]
domain_orig[W]
expires[RW]
http_only[W]
name[RW]
override[W]
path[RW]
path_orig[W]
secure[W]
use[W]
value[RW]
Public Class Methods
new()
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 76 def initialize @name = @value = @domain = @path = nil @expires = nil @url = nil @use = @secure = @http_only = @discard = @domain_orig = @path_orig = @override = nil end
parse(str, url)
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 70 def self.parse(str, url) cookie = new cookie.parse(str, url) cookie end
Public Instance Methods
discard?()
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 83 def discard? @discard end
domain()
click to toggle source
# File lib/httpclient/cookie.rb, line 199 def domain warning('Cookie#domain returns dot-less domain name now. Use Cookie#dot_domain if you need "." at the beginning.') self.original_domain end
Also aliased as: original_domain
domain_orig?()
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 99 def domain_orig? @domain_orig end
flag()
click to toggle source
# File lib/httpclient/cookie.rb, line 204 def flag deprecated('flag', 'secure, for_domain, etc.') HTTPClient::WebAgentSaver.flag(self) end
http_only?()
click to toggle source
# File lib/httpclient/cookie.rb, line 192 def http_only? deprecated('http_only?', 'httponly?') self.httponly? end
join_quotedstr(array, sep)
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 146 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)
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 134 def match?(url) domainname = url.host if (!domainname || !domain_match(domainname, @domain) || (@path && !head_match?(@path, url.path.empty? ? '/' : url.path)) || (@secure && (url.scheme != 'https')) ) return false else return true end end
override?()
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 107 def override? @override end
parse(str, url)
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 170 def parse(str, url) @url = url # TODO: should not depend on join_quotedstr. scan with escape like CSV. cookie_elem = str.split(/;/) cookie_elem = join_quotedstr(cookie_elem, ';') cookie_elem -= [""] # del empty elements, a cookie might included ";;" first_elem = cookie_elem.shift if first_elem !~ /([^=]*)(\=(.*))?/ return ## raise ArgumentError 'invalid cookie value' end @name = $1.strip @value = normalize_cookie_value($3) cookie_elem.each{|pair| key, value = pair.split(/=/, 2) ## value may nil key.strip! value = normalize_cookie_value(value) case key.downcase when 'domain' @domain = value when 'expires' @expires = nil begin @expires = Time.parse(value).gmtime if value rescue ArgumentError end when 'path' @path = value when 'secure' @secure = true ## value may nil, but must 'true'. when 'httponly' @http_only = true ## value may nil, but must 'true'. else warn("Unknown key: #{key} = #{value}") end } end
path_orig?()
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 103 def path_orig? @path_orig end
secure?()
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 91 def secure? @secure end
set_flag(flag)
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 123 def set_flag(flag) flag = flag.to_i @use = true if flag & USE > 0 @secure = true if flag & SECURE > 0 @http_only = true if flag & HTTP_ONLY > 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
url()
click to toggle source
# File lib/httpclient/cookie.rb, line 182 def url deprecated('url', 'origin') self.origin end
url=(url)
click to toggle source
# File lib/httpclient/cookie.rb, line 187 def url=(url) deprecated('url=', 'origin=') self.origin = url end
use?()
click to toggle source
# File lib/httpclient/webagent-cookie.rb, line 87 def use? @use end
Private Instance Methods
deprecated(old, new)
click to toggle source
# File lib/httpclient/cookie.rb, line 211 def deprecated(old, new) warning("WebAgent::Cookie is deprecated and will be replaced with HTTP::Cookie in the near future. Please use Cookie##{new} instead of Cookie##{old} for the replacement.") end