From bea9b1b5029a8a22d8097af405d771494e894fc4 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Wed, 27 Mar 2013 15:05:54 +0900 Subject: [PATCH] each, cleanup: Fix the base date for expiration when the method starts. This change is to remove an assumption that the clock is monotonic. --- lib/http/cookie_jar/hash_store.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/http/cookie_jar/hash_store.rb b/lib/http/cookie_jar/hash_store.rb index 848dc6b..3cadecf 100644 --- a/lib/http/cookie_jar/hash_store.rb +++ b/lib/http/cookie_jar/hash_store.rb @@ -53,6 +53,7 @@ class HTTP::CookieJar private :delete def each(uri = nil) + now = Time.now if uri thost = DomainName.new(uri.host) tpath = uri.path @@ -61,11 +62,11 @@ class HTTP::CookieJar paths.each { |path, hash| next unless HTTP::Cookie.path_match?(path, tpath) hash.delete_if { |name, cookie| - if cookie.expired? + if cookie.expired?(now) true else if cookie.valid_for_uri?(uri) - cookie.accessed_at = Time.now + cookie.accessed_at = now yield cookie end false @@ -77,7 +78,7 @@ class HTTP::CookieJar @jar.each { |domain, paths| paths.each { |path, hash| hash.delete_if { |name, cookie| - if cookie.expired? + if cookie.expired?(now) true else yield cookie @@ -100,14 +101,14 @@ class HTTP::CookieJar end def cleanup(session = false) + now = Time.now all_cookies = [] - @jar.each { |domain, paths| domain_cookies = [] paths.each { |path, hash| hash.delete_if { |name, cookie| - if cookie.expired? || (session && cookie.session?) + if cookie.expired?(now) || (session && cookie.session?) true else domain_cookies << cookie