Add HTTP::Cookie#dot_domain.

This commit is contained in:
Akinori MUSHA 2013-03-26 01:48:27 +09:00
parent f5bc5032dd
commit f2ea366de2
2 changed files with 9 additions and 0 deletions

View file

@ -386,6 +386,12 @@ class HTTP::Cookie
@domain = @domain_name.hostname
end
# Returns the domain, with a dot prefixed only if the domain flag is
# on.
def dot_domain
@for_domain ? '.' << @domain : @domain
end
# Returns the domain attribute value as a DomainName object.
attr_reader :domain_name

View file

@ -162,6 +162,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal 'example.com', cookie.domain
assert cookie.for_domain?
assert_equal '.example.com', cookie.dot_domain
end
def test_parse_domain_no_dot
@ -173,6 +174,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal 'example.com', cookie.domain
assert cookie.for_domain?
assert_equal '.example.com', cookie.dot_domain
end
def test_parse_domain_none
@ -184,6 +186,7 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal 'example.com', cookie.domain
assert !cookie.for_domain?
assert_equal 'example.com', cookie.dot_domain
end
def test_parse_max_age