mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
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.
This commit is contained in:
parent
bd3ae6c1ae
commit
299bb24550
1 changed files with 11 additions and 10 deletions
|
|
@ -40,17 +40,18 @@ class HTTP::CookieJar
|
||||||
|
|
||||||
def add(cookie)
|
def add(cookie)
|
||||||
path_cookies = ((@jar[cookie.domain_name.hostname] ||= {})[cookie.path] ||= {})
|
path_cookies = ((@jar[cookie.domain_name.hostname] ||= {})[cookie.path] ||= {})
|
||||||
|
|
||||||
if cookie.expired?
|
|
||||||
path_cookies.delete(cookie.name)
|
|
||||||
else
|
|
||||||
path_cookies[cookie.name] = cookie
|
path_cookies[cookie.name] = cookie
|
||||||
cleanup if (@gc_index += 1) >= GC_THRESHOLD
|
cleanup if (@gc_index += 1) >= GC_THRESHOLD
|
||||||
end
|
|
||||||
|
|
||||||
self
|
self
|
||||||
end
|
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)
|
def each(uri = nil)
|
||||||
if uri
|
if uri
|
||||||
thost = DomainName.new(uri.host)
|
thost = DomainName.new(uri.host)
|
||||||
|
|
@ -118,7 +119,7 @@ class HTTP::CookieJar
|
||||||
if (debt = domain_cookies.size - HTTP::Cookie::MAX_COOKIES_PER_DOMAIN) > 0
|
if (debt = domain_cookies.size - HTTP::Cookie::MAX_COOKIES_PER_DOMAIN) > 0
|
||||||
domain_cookies.sort_by!(&:created_at)
|
domain_cookies.sort_by!(&:created_at)
|
||||||
domain_cookies.slice!(0, debt).each { |cookie|
|
domain_cookies.slice!(0, debt).each { |cookie|
|
||||||
add(cookie.expire!)
|
delete(cookie)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -128,7 +129,7 @@ class HTTP::CookieJar
|
||||||
if (debt = all_cookies.size - HTTP::Cookie::MAX_COOKIES_TOTAL) > 0
|
if (debt = all_cookies.size - HTTP::Cookie::MAX_COOKIES_TOTAL) > 0
|
||||||
all_cookies.sort_by!(&:created_at)
|
all_cookies.sort_by!(&:created_at)
|
||||||
all_cookies.slice!(0, debt).each { |cookie|
|
all_cookies.slice!(0, debt).each { |cookie|
|
||||||
add(cookie.expire!)
|
delete(cookie)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue