From 299bb245508f9ae50ac6f5b8da169c19fcb35c0e Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Wed, 27 Mar 2013 14:58:22 +0900 Subject: [PATCH] add(): Stop deleting an existing cookie when storing an expired cookie. This is a backout of what I've done previously. Expiration check is better done in extraction where a user can optionally specify a base date. Add an internal method delete() to delete an existing cookie. --- lib/http/cookie_jar/hash_store.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/http/cookie_jar/hash_store.rb b/lib/http/cookie_jar/hash_store.rb index fa3bf36..848dc6b 100644 --- a/lib/http/cookie_jar/hash_store.rb +++ b/lib/http/cookie_jar/hash_store.rb @@ -40,17 +40,18 @@ class HTTP::CookieJar def add(cookie) path_cookies = ((@jar[cookie.domain_name.hostname] ||= {})[cookie.path] ||= {}) - - if cookie.expired? - path_cookies.delete(cookie.name) - else - path_cookies[cookie.name] = cookie - cleanup if (@gc_index += 1) >= GC_THRESHOLD - end - + path_cookies[cookie.name] = cookie + cleanup if (@gc_index += 1) >= GC_THRESHOLD self end + def delete(cookie) + path_cookies = ((@jar[cookie.domain_name.hostname] ||= {})[cookie.path] ||= {}) + path_cookies.delete(cookie.name) + self + end + private :delete + def each(uri = nil) if uri thost = DomainName.new(uri.host) @@ -118,7 +119,7 @@ class HTTP::CookieJar if (debt = domain_cookies.size - HTTP::Cookie::MAX_COOKIES_PER_DOMAIN) > 0 domain_cookies.sort_by!(&:created_at) domain_cookies.slice!(0, debt).each { |cookie| - add(cookie.expire!) + delete(cookie) } end @@ -128,7 +129,7 @@ class HTTP::CookieJar if (debt = all_cookies.size - HTTP::Cookie::MAX_COOKIES_TOTAL) > 0 all_cookies.sort_by!(&:created_at) all_cookies.slice!(0, debt).each { |cookie| - add(cookie.expire!) + delete(cookie) } end