diff --git a/lib/http/cookie.rb b/lib/http/cookie.rb index fb2056e..f32a923 100644 --- a/lib/http/cookie.rb +++ b/lib/http/cookie.rb @@ -12,6 +12,8 @@ class HTTP::Cookie # Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at least) MAX_LENGTH = 4096 + UNIX_EPOCH = Time.at(0) + PERSISTENT_PROPERTIES = %w[ name value domain for_domain path @@ -347,6 +349,11 @@ class HTTP::Cookie Time.now > @expires end + def expire + @expires = UNIX_EPOCH + self + end + alias secure? secure alias httponly? httponly alias session? session diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index bf9edba..ef8489b 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -447,6 +447,14 @@ class TestHTTPCookie < Test::Unit::TestCase }) 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 assert_not_equal(HTTP::Cookie.new(cookie_values), HTTP::Cookie.new(cookie_values(:value => 'bar')))