Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Apr 11, 2013
@shugo shugo Expire old cookies before finding a cookie in CookieManager#add.
Before this fix, CookieManager#add find a cookie, and then expire old cookies,
so the found cookie might be removed before being updated.
d20462c
Commits on Dec 02, 2013
@nahi Merge pull request #154 from shugo/master
A new cookie never be accepted if an HTTPClient has the same expired cookie.
d78643b
Showing with 22 additions and 1 deletion.
  1. +1 −1 lib/httpclient/cookie.rb
  2. +21 −0 test/test_cookie.rb
View
2 lib/httpclient/cookie.rb
@@ -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
}
@@ -311,7 +312,6 @@ def add(given)
cookie.use = true
@cookies << cookie
end
- check_expired_cookies
end
cookie.domain = domain
View
21 test/test_cookie.rb
@@ -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/"))

No commit comments for this range

Something went wrong with that request. Please try again.