Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new cookie never be accepted if an HTTPClient has the same expired cookie. #154

Merged
merged 1 commit into from
Dec 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/httpclient/cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def add(given)

cookie = nil
@cookies.synchronize do
check_expired_cookies
cookie = @cookies.find { |c|
c.domain == domain && c.path == path && c.name == given.name
}
Expand All @@ -311,7 +312,6 @@ def add(given)
cookie.use = true
@cookies << cookie
end
check_expired_cookies
end

cookie.domain = domain
Expand Down
21 changes: 21 additions & 0 deletions test/test_cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,27 @@ def test_parse_expires
assert_equal("/", cookie.path)
end

def test_parse_after_expiration
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2010 00:00:00 GMT; path=/"
@cm.parse(str, urify('http://www.test.jp'))
cookie = @cm.cookies[0]
assert_instance_of(WebAgent::Cookie, cookie)
assert_equal("inkid", cookie.name)
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
assert_equal(Time.gm(2010, 12, 1, 0,0,0), cookie.expires)
assert_equal("/", cookie.path)

time = Time.now.utc.round + 60
expires = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=#{expires}; path=/"
@cm.parse(str, urify('http://www.test.jp'))
cookie = @cm.cookies[0]
assert_equal("inkid", cookie.name)
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
assert_equal(time, cookie.expires)
assert_equal("/", cookie.path)
end

def test_find_cookie()
str = "xmen=off,0,0,1; path=/; domain=.excite2.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
@cm.parse(str, urify("http://www.excite2.co.jp/"))
Expand Down