mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
each, cleanup: Fix the base date for expiration when the method starts.
This change is to remove an assumption that the clock is monotonic.
This commit is contained in:
parent
299bb24550
commit
bea9b1b502
1 changed files with 6 additions and 5 deletions
|
|
@ -53,6 +53,7 @@ class HTTP::CookieJar
|
||||||
private :delete
|
private :delete
|
||||||
|
|
||||||
def each(uri = nil)
|
def each(uri = nil)
|
||||||
|
now = Time.now
|
||||||
if uri
|
if uri
|
||||||
thost = DomainName.new(uri.host)
|
thost = DomainName.new(uri.host)
|
||||||
tpath = uri.path
|
tpath = uri.path
|
||||||
|
|
@ -61,11 +62,11 @@ class HTTP::CookieJar
|
||||||
paths.each { |path, hash|
|
paths.each { |path, hash|
|
||||||
next unless HTTP::Cookie.path_match?(path, tpath)
|
next unless HTTP::Cookie.path_match?(path, tpath)
|
||||||
hash.delete_if { |name, cookie|
|
hash.delete_if { |name, cookie|
|
||||||
if cookie.expired?
|
if cookie.expired?(now)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
if cookie.valid_for_uri?(uri)
|
if cookie.valid_for_uri?(uri)
|
||||||
cookie.accessed_at = Time.now
|
cookie.accessed_at = now
|
||||||
yield cookie
|
yield cookie
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
|
|
@ -77,7 +78,7 @@ class HTTP::CookieJar
|
||||||
@jar.each { |domain, paths|
|
@jar.each { |domain, paths|
|
||||||
paths.each { |path, hash|
|
paths.each { |path, hash|
|
||||||
hash.delete_if { |name, cookie|
|
hash.delete_if { |name, cookie|
|
||||||
if cookie.expired?
|
if cookie.expired?(now)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
yield cookie
|
yield cookie
|
||||||
|
|
@ -100,14 +101,14 @@ class HTTP::CookieJar
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup(session = false)
|
def cleanup(session = false)
|
||||||
|
now = Time.now
|
||||||
all_cookies = []
|
all_cookies = []
|
||||||
|
|
||||||
@jar.each { |domain, paths|
|
@jar.each { |domain, paths|
|
||||||
domain_cookies = []
|
domain_cookies = []
|
||||||
|
|
||||||
paths.each { |path, hash|
|
paths.each { |path, hash|
|
||||||
hash.delete_if { |name, cookie|
|
hash.delete_if { |name, cookie|
|
||||||
if cookie.expired? || (session && cookie.session?)
|
if cookie.expired?(now) || (session && cookie.session?)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
domain_cookies << cookie
|
domain_cookies << cookie
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue