Object
# File lib/httpclient/cookie.rb, line 223 223: def initialize(file=nil) 224: @cookies = Array.new() 225: @cookies.extend(MonitorMixin) 226: @cookies_file = file 227: @is_saved = true 228: @reject_domains = Array.new() 229: @accept_domains = Array.new() 230: @netscape_rule = false 231: end
# File lib/httpclient/cookie.rb, line 328 328: def add(cookie) 329: url = cookie.url 330: name, value = cookie.name, cookie.value 331: expires, domain, path = 332: cookie.expires, cookie.domain, cookie.path 333: secure, domain_orig, path_orig = 334: cookie.secure?, cookie.domain_orig?, cookie.path_orig? 335: discard, override = 336: cookie.discard?, cookie.override? 337: 338: domainname = url.host 339: domain_orig, path_orig = domain, path 340: use_security = override 341: 342: if domain 343: 344: # [DRAFT 12] s. 4.2.2 (does not apply in the case that 345: # host name is the same as domain attribute for version 0 346: # cookie) 347: # I think that this rule has almost the same effect as the 348: # tail match of [NETSCAPE]. 349: if domain !~ /^\./ && domainname != domain 350: domain = '.'+domain 351: end 352: 353: # [NETSCAPE] rule 354: if @netscape_rule 355: n = total_dot_num(domain) 356: if n < 2 357: cookie_error(SpecialError.new(), override) 358: elsif n == 2 359: ## [NETSCAPE] rule 360: ok = SPECIAL_DOMAIN.select{|sdomain| 361: sdomain == domain[-(sdomain.length)..1] 362: } 363: if ok.empty? 364: cookie_error(SpecialError.new(), override) 365: end 366: end 367: end 368: 369: # this implementation does not check RFC2109 4.3.2 case 2; 370: # the portion of host not in domain does not contain a dot. 371: # according to nsCookieService.cpp in Firefox 3.0.4, Firefox 3.0.4 372: # and IE does not check, too. 373: end 374: 375: path ||= url.path.sub(%/[^/]*|, '') 376: domain ||= domainname 377: @cookies.synchronize do 378: cookie = find_cookie_info(domain, path, name) 379: if !cookie 380: cookie = WebAgent::Cookie.new() 381: cookie.use = true 382: @cookies << cookie 383: end 384: check_expired_cookies() 385: end 386: 387: cookie.url = url 388: cookie.name = name 389: cookie.value = value 390: cookie.expires = expires 391: cookie.domain = domain 392: cookie.path = path 393: 394: ## for flag 395: cookie.secure = secure 396: cookie.domain_orig = domain_orig 397: cookie.path_orig = path_orig 398: if discard || cookie.expires == nil 399: cookie.discard = true 400: else 401: cookie.discard = false 402: @is_saved = false 403: end 404: end
# File lib/httpclient/cookie.rb, line 298 298: def find(url) 299: return nil if @cookies.empty? 300: 301: cookie_list = Array.new() 302: @cookies.each{|cookie| 303: is_expired = (cookie.expires && (cookie.expires < Time.now.gmtime)) 304: if cookie.use? && !is_expired && cookie.match?(url) 305: if cookie_list.select{|c1| c1.name == cookie.name}.empty? 306: cookie_list << cookie 307: end 308: end 309: } 310: return make_cookie_str(cookie_list) 311: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.