for conformance to wp.netscape.com/newsref/std/cookie_spec.html
# File lib/httpclient/cookie.rb, line 224 def initialize(file=nil) @cookies = Array.new @cookies.extend(MonitorMixin) @cookies_file = file @is_saved = true @reject_domains = Array.new @accept_domains = Array.new @netscape_rule = false end
# File lib/httpclient/cookie.rb, line 298 def add(given) check_domain(given.domain, given.url.host, given.override?) domain = given.domain || given.url.host path = given.path || given.url.path.sub(%r/[^/]*\z|, '') cookie = nil @cookies.synchronize do check_expired_cookies cookie = @cookies.find { |c| c.domain == domain && c.path == path && c.name == given.name } if !cookie cookie = WebAgent::Cookie.new cookie.use = true @cookies << cookie end end cookie.domain = domain cookie.path = path cookie.url = given.url cookie.name = given.name cookie.value = given.value cookie.expires = given.expires cookie.secure = given.secure? cookie.http_only = given.http_only? cookie.domain_orig = given.domain cookie.path_orig = given.path if cookie.discard? || cookie.expires == nil cookie.discard = true else cookie.discard = false @is_saved = false end end
# File lib/httpclient/cookie.rb, line 283 def find(url) return nil if @cookies.empty? cookie_list = Array.new @cookies.each{|cookie| is_expired = (cookie.expires && (cookie.expires < Time.now.gmtime)) if cookie.use? && !is_expired && cookie.match?(url) if cookie_list.select{|c1| c1.name == cookie.name}.empty? cookie_list << cookie end end } return make_cookie_str(cookie_list) end
# File lib/httpclient/cookie.rb, line 277 def parse(str, url) cookie = WebAgent::Cookie.new cookie.parse(str, url) add(cookie) end
# File lib/httpclient/cookie.rb, line 399 def check_domain(domain, hostname, override) return unless domain # [DRAFT 12] s. 4.2.2 (does not apply in the case that # host name is the same as domain attribute for version 0 # cookie) # I think that this rule has almost the same effect as the # tail match of [NETSCAPE]. if domain !~ /^\./ && hostname != domain domain = '.'+domain end # [NETSCAPE] rule if @netscape_rule n = domain.scan(/\./).length if n < 2 cookie_error(SpecialError.new, override) elsif n == 2 ## [NETSCAPE] rule ok = SPECIAL_DOMAIN.select{|sdomain| sdomain == domain[-(sdomain.length)..-1] } if ok.empty? cookie_error(SpecialError.new, override) end end end # this implementation does not check RFC2109 4.3.2 case 2; # the portion of host not in domain does not contain a dot. # according to nsCookieService.cpp in Firefox 3.0.4, Firefox 3.0.4 # and IE does not check, too. end