mirror of https://github.com/aria2/aria2
2008-09-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Parse `expires' of Set-Cookie using Time::parseHTTPDate() * src/CookieParser.cc * test/CookieParserTest.cc * test/HttpResponseTest.ccpull/1/head
parent
69b18308d9
commit
b624a12ed0
|
@ -1,3 +1,10 @@
|
|||
2008-09-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Parse `expires' of Set-Cookie using Time::parseHTTPDate()
|
||||
* src/CookieParser.cc
|
||||
* test/CookieParserTest.cc
|
||||
* test/HttpResponseTest.cc
|
||||
|
||||
2008-09-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Implmented the functions to parse date.
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "CookieParser.h"
|
||||
#include "Util.h"
|
||||
#include "A2STR.h"
|
||||
#include "TimeA2.h"
|
||||
#include <strings.h>
|
||||
#include <utility>
|
||||
#include <istream>
|
||||
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;");
|
||||
|
||||
|
|
Loading…
Reference in New Issue