From b624a12ed02e830d1ab8f0ad57f6cb136a7ceef8 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 7 Sep 2008 04:36:41 +0000 Subject: [PATCH] 2008-09-07 Tatsuhiro Tsujikawa Parse `expires' of Set-Cookie using Time::parseHTTPDate() * src/CookieParser.cc * test/CookieParserTest.cc * test/HttpResponseTest.cc --- ChangeLog | 7 +++++++ src/CookieParser.cc | 3 ++- test/CookieParserTest.cc | 15 +++++++++++++-- test/HttpResponseTest.cc | 4 ++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1277f57..a2ba6982 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-09-07 Tatsuhiro Tsujikawa + + Parse `expires' of Set-Cookie using Time::parseHTTPDate() + * src/CookieParser.cc + * test/CookieParserTest.cc + * test/HttpResponseTest.cc + 2008-09-07 Tatsuhiro Tsujikawa Implmented the functions to parse date. diff --git a/src/CookieParser.cc b/src/CookieParser.cc index a43d1260..d009ad38 100644 --- a/src/CookieParser.cc +++ b/src/CookieParser.cc @@ -35,6 +35,7 @@ #include "CookieParser.h" #include "Util.h" #include "A2STR.h" +#include "TimeA2.h" #include #include #include @@ -77,7 +78,7 @@ Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defa } time_t expiry = -1; if(values.find(C_EXPIRES) != values.end()) { - expiry = Util::httpGMT(values[C_EXPIRES]); + expiry = Time::parseHTTPDate(values[C_EXPIRES]).getTime(); } if(expiry == -1) { return Cookie(nameValue.first, nameValue.second, diff --git a/test/CookieParserTest.cc b/test/CookieParserTest.cc index 4c027bf1..7c2dd64a 100644 --- a/test/CookieParserTest.cc +++ b/test/CookieParserTest.cc @@ -26,7 +26,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( CookieParserTest ); void CookieParserTest::testParse() { - std::string str = "JSESSIONID=123456789; expires=Sun, 2007-06-10 11:00:00 GMT; path=/; domain=localhost; secure"; + std::string str = "JSESSIONID=123456789; expires=Sun, 10-Jun-2007 11:00:00 GMT; path=/; domain=localhost; secure"; Cookie c = CookieParser().parse(str); CPPUNIT_ASSERT(c.good()); CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName()); @@ -52,10 +52,21 @@ void CookieParserTest::testParse() c = CookieParser().parse(str3); CPPUNIT_ASSERT(!c.good()); - std::string str4 = "UID=300; expires=Wed, 1890-01-01 0:0:0 GMT;"; + std::string str4 = "UID=300; expires=Wed, 01-Jan-1890 00:00:00 GMT;"; c = CookieParser().parse(str4, "localhost", "/"); CPPUNIT_ASSERT(c.good()); CPPUNIT_ASSERT(c.isOnetimeCookie()); + + std::string str5 = "k=v; expires=Sun, 10-Jun-07 11:00:00 GMT"; + c = CookieParser().parse(str5); + CPPUNIT_ASSERT(c.good()); + CPPUNIT_ASSERT_EQUAL(std::string("k"), c.getName()); + CPPUNIT_ASSERT_EQUAL(std::string("v"), c.getValue()); + CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.getExpiry()); + CPPUNIT_ASSERT_EQUAL(std::string(""), c.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string(""), c.getPath()); + CPPUNIT_ASSERT(!c.isSecureCookie()); + CPPUNIT_ASSERT(!c.isOnetimeCookie()); } void CookieParserTest::testParse_file() diff --git a/test/HttpResponseTest.cc b/test/HttpResponseTest.cc index 496d8e37..6a2ffbcf 100644 --- a/test/HttpResponseTest.cc +++ b/test/HttpResponseTest.cc @@ -471,9 +471,9 @@ void HttpResponseTest::testRetrieveCookie() httpRequest->setCookieStorage(st); httpResponse.setHttpRequest(httpRequest); - httpHeader->put("Set-Cookie", "k1=v1; expires=Sun, 2007-06-10 11:00:00 GMT;" + httpHeader->put("Set-Cookie", "k1=v1; expires=Sun, 10-Jun-2007 11:00:00 GMT;" "path=/; domain=.aria2.org;"); - httpHeader->put("Set-Cookie", "k2=v2; expires=Sun, 2038-01-01 00:00:00 GMT;" + httpHeader->put("Set-Cookie", "k2=v2; expires=Sun, 01-Jan-09 00:00:00 GMT;" "path=/; domain=.aria2.org;"); httpHeader->put("Set-Cookie", "k3=v3;");