mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Include MonitorMixin in store classes and make them thread-safe.
This commit is contained in:
parent
30e2915c1e
commit
add4a367fd
3 changed files with 79 additions and 58 deletions
|
|
@ -1,4 +1,8 @@
|
|||
require 'monitor'
|
||||
|
||||
class HTTP::CookieJar::AbstractStore
|
||||
include MonitorMixin
|
||||
|
||||
class << self
|
||||
@@class_map = {}
|
||||
|
||||
|
|
@ -31,6 +35,7 @@ class HTTP::CookieJar::AbstractStore
|
|||
private :default_options
|
||||
|
||||
def initialize(options = nil)
|
||||
super() # MonitorMixin
|
||||
options ||= {}
|
||||
@logger = options[:logger]
|
||||
# Initializes each instance variable of the same name as option
|
||||
|
|
@ -65,7 +70,13 @@ class HTTP::CookieJar::AbstractStore
|
|||
# If (and only if) the +uri+ option is given, last access time of
|
||||
# each cookie is updated to the current time.
|
||||
def each(uri = nil, &block)
|
||||
if uri
|
||||
raise
|
||||
else
|
||||
synchronize {
|
||||
raise
|
||||
}
|
||||
end
|
||||
self
|
||||
end
|
||||
include Enumerable
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ class HTTP::CookieJar
|
|||
}
|
||||
}
|
||||
else
|
||||
synchronize {
|
||||
@jar.each { |domain, paths|
|
||||
paths.each { |path, hash|
|
||||
hash.delete_if { |name, cookie|
|
||||
|
|
@ -93,6 +94,7 @@ class HTTP::CookieJar
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
self
|
||||
end
|
||||
|
|
@ -109,6 +111,10 @@ class HTTP::CookieJar
|
|||
def cleanup(session = false)
|
||||
now = Time.now
|
||||
all_cookies = []
|
||||
|
||||
synchronize {
|
||||
break if @gc_index == 0
|
||||
|
||||
@jar.each { |domain, paths|
|
||||
domain_cookies = []
|
||||
|
||||
|
|
@ -148,6 +154,8 @@ class HTTP::CookieJar
|
|||
}
|
||||
|
||||
@gc_index = 0
|
||||
}
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -335,9 +335,6 @@ class HTTP::CookieJar
|
|||
end
|
||||
|
||||
def cleanup(session = false)
|
||||
now = Time.now
|
||||
all_cookies = []
|
||||
|
||||
@st_delete_expired ||=
|
||||
@db.prepare("DELETE FROM moz_cookies WHERE expiry < :expiry")
|
||||
|
||||
|
|
@ -364,7 +361,10 @@ class HTTP::CookieJar
|
|||
)
|
||||
SQL
|
||||
|
||||
@st_delete_expired.execute({ 'expiry' => now.to_i })
|
||||
synchronize {
|
||||
break if @gc_index == 0
|
||||
|
||||
@st_delete_expired.execute({ 'expiry' => Time.now.to_i })
|
||||
|
||||
@st_overusing_domains.execute({
|
||||
'count' => HTTP::Cookie::MAX_COOKIES_PER_DOMAIN
|
||||
|
|
@ -384,6 +384,8 @@ class HTTP::CookieJar
|
|||
end
|
||||
|
||||
@gc_index = 0
|
||||
}
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue