From f2ea366de2f4b05b6d59043717bb61d79e546e46 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Tue, 26 Mar 2013 01:48:27 +0900 Subject: [PATCH] Add HTTP::Cookie#dot_domain. --- lib/http/cookie.rb | 6 ++++++ test/test_http_cookie.rb | 3 +++ 2 files changed, 9 insertions(+) diff --git a/lib/http/cookie.rb b/lib/http/cookie.rb index 70336ad..8fcd4a7 100644 --- a/lib/http/cookie.rb +++ b/lib/http/cookie.rb @@ -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 diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index d0b43a4..fd00076 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -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