mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
Make GC threshold user specifiable.
This commit is contained in:
parent
823c2a15e0
commit
6fade20c59
3 changed files with 16 additions and 11 deletions
|
|
@ -9,11 +9,12 @@ end
|
|||
# :startdoc:
|
||||
|
||||
class HTTP::CookieJar
|
||||
# A store class that uses a hash of hashes.
|
||||
class HashStore < AbstractStore
|
||||
GC_THRESHOLD = HTTP::Cookie::MAX_COOKIES_TOTAL / 20
|
||||
|
||||
def default_options
|
||||
{}
|
||||
{
|
||||
:gc_threshold => HTTP::Cookie::MAX_COOKIES_TOTAL / 20
|
||||
}
|
||||
end
|
||||
|
||||
def initialize(options = nil)
|
||||
|
|
@ -41,7 +42,7 @@ class HTTP::CookieJar
|
|||
def add(cookie)
|
||||
path_cookies = ((@jar[cookie.domain_name.hostname] ||= {})[cookie.path] ||= {})
|
||||
path_cookies[cookie.name] = cookie
|
||||
cleanup if (@gc_index += 1) >= GC_THRESHOLD
|
||||
cleanup if (@gc_index += 1) >= @gc_threshold
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@ class HTTP::CookieJar
|
|||
class MozillaStore < AbstractStore
|
||||
SCHEMA_VERSION = 5
|
||||
|
||||
GC_THRESHOLD = HTTP::Cookie::MAX_COOKIES_TOTAL / 20
|
||||
|
||||
def default_options
|
||||
{
|
||||
:gc_threshold => HTTP::Cookie::MAX_COOKIES_TOTAL / 20,
|
||||
:app_id => 0,
|
||||
:in_browser_element => false,
|
||||
}
|
||||
|
|
@ -170,7 +169,7 @@ class HTTP::CookieJar
|
|||
:isSecure => cookie.secure? ? 1 : 0,
|
||||
:isHttpOnly => cookie.httponly? ? 1 : 0,
|
||||
})
|
||||
cleanup if (@gc_index += 1) >= GC_THRESHOLD
|
||||
cleanup if (@gc_index += 1) >= @gc_threshold
|
||||
|
||||
self
|
||||
end
|
||||
|
|
|
|||
|
|
@ -589,16 +589,21 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_max_cookies_hashstore
|
||||
gc_threshold = 150
|
||||
h_test_max_cookies(
|
||||
HTTP::CookieJar.new,
|
||||
HTTP::Cookie::MAX_COOKIES_TOTAL + HTTP::CookieJar::HashStore::GC_THRESHOLD)
|
||||
HTTP::CookieJar.new(:hash,
|
||||
:gc_threshold => gc_threshold),
|
||||
HTTP::Cookie::MAX_COOKIES_TOTAL + gc_threshold)
|
||||
end
|
||||
|
||||
def test_max_cookies_mozillastore
|
||||
gc_threshold = 150
|
||||
Dir.mktmpdir { |dir|
|
||||
h_test_max_cookies(
|
||||
HTTP::CookieJar.new(:mozilla, :filename => File.join(dir, "cookies.sqlite")),
|
||||
HTTP::Cookie::MAX_COOKIES_TOTAL + HTTP::CookieJar::MozillaStore::GC_THRESHOLD)
|
||||
HTTP::CookieJar.new(:mozilla,
|
||||
:gc_threshold => gc_threshold,
|
||||
:filename => File.join(dir, "cookies.sqlite")),
|
||||
HTTP::Cookie::MAX_COOKIES_TOTAL + gc_threshold)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue