mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +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:
|
# :startdoc:
|
||||||
|
|
||||||
class HTTP::CookieJar
|
class HTTP::CookieJar
|
||||||
|
# A store class that uses a hash of hashes.
|
||||||
class HashStore < AbstractStore
|
class HashStore < AbstractStore
|
||||||
GC_THRESHOLD = HTTP::Cookie::MAX_COOKIES_TOTAL / 20
|
|
||||||
|
|
||||||
def default_options
|
def default_options
|
||||||
{}
|
{
|
||||||
|
:gc_threshold => HTTP::Cookie::MAX_COOKIES_TOTAL / 20
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(options = nil)
|
def initialize(options = nil)
|
||||||
|
|
@ -41,7 +42,7 @@ 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] ||= {})
|
||||||
path_cookies[cookie.name] = cookie
|
path_cookies[cookie.name] = cookie
|
||||||
cleanup if (@gc_index += 1) >= GC_THRESHOLD
|
cleanup if (@gc_index += 1) >= @gc_threshold
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,9 @@ class HTTP::CookieJar
|
||||||
class MozillaStore < AbstractStore
|
class MozillaStore < AbstractStore
|
||||||
SCHEMA_VERSION = 5
|
SCHEMA_VERSION = 5
|
||||||
|
|
||||||
GC_THRESHOLD = HTTP::Cookie::MAX_COOKIES_TOTAL / 20
|
|
||||||
|
|
||||||
def default_options
|
def default_options
|
||||||
{
|
{
|
||||||
|
:gc_threshold => HTTP::Cookie::MAX_COOKIES_TOTAL / 20,
|
||||||
:app_id => 0,
|
:app_id => 0,
|
||||||
:in_browser_element => false,
|
:in_browser_element => false,
|
||||||
}
|
}
|
||||||
|
|
@ -170,7 +169,7 @@ class HTTP::CookieJar
|
||||||
:isSecure => cookie.secure? ? 1 : 0,
|
:isSecure => cookie.secure? ? 1 : 0,
|
||||||
:isHttpOnly => cookie.httponly? ? 1 : 0,
|
:isHttpOnly => cookie.httponly? ? 1 : 0,
|
||||||
})
|
})
|
||||||
cleanup if (@gc_index += 1) >= GC_THRESHOLD
|
cleanup if (@gc_index += 1) >= @gc_threshold
|
||||||
|
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -589,16 +589,21 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_max_cookies_hashstore
|
def test_max_cookies_hashstore
|
||||||
|
gc_threshold = 150
|
||||||
h_test_max_cookies(
|
h_test_max_cookies(
|
||||||
HTTP::CookieJar.new,
|
HTTP::CookieJar.new(:hash,
|
||||||
HTTP::Cookie::MAX_COOKIES_TOTAL + HTTP::CookieJar::HashStore::GC_THRESHOLD)
|
:gc_threshold => gc_threshold),
|
||||||
|
HTTP::Cookie::MAX_COOKIES_TOTAL + gc_threshold)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_max_cookies_mozillastore
|
def test_max_cookies_mozillastore
|
||||||
|
gc_threshold = 150
|
||||||
Dir.mktmpdir { |dir|
|
Dir.mktmpdir { |dir|
|
||||||
h_test_max_cookies(
|
h_test_max_cookies(
|
||||||
HTTP::CookieJar.new(:mozilla, :filename => File.join(dir, "cookies.sqlite")),
|
HTTP::CookieJar.new(:mozilla,
|
||||||
HTTP::Cookie::MAX_COOKIES_TOTAL + HTTP::CookieJar::MozillaStore::GC_THRESHOLD)
|
:gc_threshold => gc_threshold,
|
||||||
|
:filename => File.join(dir, "cookies.sqlite")),
|
||||||
|
HTTP::Cookie::MAX_COOKIES_TOTAL + gc_threshold)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue