mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Add HTTP::Cookie#expire.
This commit is contained in:
parent
91193dace3
commit
d8be652a92
2 changed files with 15 additions and 0 deletions
|
|
@ -12,6 +12,8 @@ class HTTP::Cookie
|
||||||
# Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at least)
|
# Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at least)
|
||||||
MAX_LENGTH = 4096
|
MAX_LENGTH = 4096
|
||||||
|
|
||||||
|
UNIX_EPOCH = Time.at(0)
|
||||||
|
|
||||||
PERSISTENT_PROPERTIES = %w[
|
PERSISTENT_PROPERTIES = %w[
|
||||||
name value
|
name value
|
||||||
domain for_domain path
|
domain for_domain path
|
||||||
|
|
@ -347,6 +349,11 @@ class HTTP::Cookie
|
||||||
Time.now > @expires
|
Time.now > @expires
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expire
|
||||||
|
@expires = UNIX_EPOCH
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
alias secure? secure
|
alias secure? secure
|
||||||
alias httponly? httponly
|
alias httponly? httponly
|
||||||
alias session? session
|
alias session? session
|
||||||
|
|
|
||||||
|
|
@ -447,6 +447,14 @@ class TestHTTPCookie < Test::Unit::TestCase
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_expiration
|
||||||
|
cookie = HTTP::Cookie.new(cookie_values)
|
||||||
|
|
||||||
|
assert_equal false, cookie.expired?
|
||||||
|
cookie.expire
|
||||||
|
assert_equal true, cookie.expired?
|
||||||
|
end
|
||||||
|
|
||||||
def test_equal
|
def test_equal
|
||||||
assert_not_equal(HTTP::Cookie.new(cookie_values),
|
assert_not_equal(HTTP::Cookie.new(cookie_values),
|
||||||
HTTP::Cookie.new(cookie_values(:value => 'bar')))
|
HTTP::Cookie.new(cookie_values(:value => 'bar')))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue