mirror of https://github.com/aria2/aria2
2008-01-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Set default domain and default path to cookie. * src/HttpResponse.cc * src/CookieBox.{h, cc} * src/CookieParser.{h, cc} * test/CookieParserTest.ccpull/1/head
parent
eafabe2d44
commit
c1bc357d79
|
@ -1,3 +1,11 @@
|
|||
2008-01-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Set default domain and default path to cookie.
|
||||
* src/HttpResponse.cc
|
||||
* src/CookieBox.{h, cc}
|
||||
* src/CookieParser.{h, cc}
|
||||
* test/CookieParserTest.cc
|
||||
|
||||
2008-01-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Added --no-conf and --conf-path command-line option.
|
||||
|
|
|
@ -44,8 +44,9 @@ void CookieBox::add(const Cookie& cookie) {
|
|||
cookies.push_back(cookie);
|
||||
}
|
||||
|
||||
void CookieBox::add(const string& cookieStr) {
|
||||
Cookie c = CookieParser().parse(cookieStr);
|
||||
void CookieBox::add(const string& cookieStr, const string& defaultDomain, const string& defaultPath)
|
||||
{
|
||||
Cookie c = CookieParser().parse(cookieStr, defaultDomain, defaultPath);
|
||||
if(c.good()) {
|
||||
cookies.push_back(c);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,8 @@ public:
|
|||
~CookieBox();
|
||||
void clear();
|
||||
void add(const Cookie& cookie);
|
||||
void add(const string& cookieStr);
|
||||
void add(const string& cookieStr,
|
||||
const string& defaultDomain, const string& defaultPath);
|
||||
void add(const Cookies& cookies);
|
||||
Cookies criteriaFind(const string& host, const string& dir, time_t date, bool secure) const;
|
||||
};
|
||||
|
|
|
@ -54,8 +54,15 @@ void CookieParser::setField(Cookie& cookie, const string& name, const string& va
|
|||
}
|
||||
|
||||
Cookie CookieParser::parse(const string& cookieStr) const
|
||||
{
|
||||
return parse(cookieStr, "", "");
|
||||
}
|
||||
|
||||
Cookie CookieParser::parse(const string& cookieStr, const string& defaultDomain, const string& defaultPath) const
|
||||
{
|
||||
Cookie cookie;
|
||||
cookie.domain = defaultDomain;
|
||||
cookie.path = defaultPath;
|
||||
Strings terms;
|
||||
Util::slice(terms, Util::trim(cookieStr), ';', true);
|
||||
for(Strings::iterator itr = terms.begin(); itr != terms.end(); itr++) {
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
|
||||
~CookieParser() {}
|
||||
|
||||
Cookie parse(const string& cookieStr, const string& defaultDomain, const string& defaultPath) const;
|
||||
|
||||
Cookie parse(const string& cookieStr) const;
|
||||
|
||||
Cookies parse(istream& s) const;
|
||||
|
|
|
@ -88,7 +88,9 @@ void HttpResponse::retrieveCookie()
|
|||
{
|
||||
Strings v = httpHeader->get("Set-Cookie");
|
||||
for(Strings::const_iterator itr = v.begin(); itr != v.end(); itr++) {
|
||||
httpRequest->getRequest()->cookieBox->add(*itr);
|
||||
string domain = httpRequest->getRequest()->getHost();
|
||||
string path = httpRequest->getDir();
|
||||
httpRequest->getRequest()->cookieBox->add(*itr, domain, path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,13 +38,13 @@ void CookieParserTest::testParse()
|
|||
CPPUNIT_ASSERT_EQUAL(false, c.onetime);
|
||||
|
||||
string str2 = "JSESSIONID=123456789";
|
||||
c = CookieParser().parse(str2);
|
||||
c = CookieParser().parse(str2, "default.domain", "/default/path");
|
||||
CPPUNIT_ASSERT(c.good());
|
||||
CPPUNIT_ASSERT_EQUAL(string("JSESSIONID"), c.name);
|
||||
CPPUNIT_ASSERT_EQUAL(string("123456789"), c.value);
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)0, c.expires);
|
||||
CPPUNIT_ASSERT_EQUAL(string(""), c.path);
|
||||
CPPUNIT_ASSERT_EQUAL(string(""), c.domain);
|
||||
CPPUNIT_ASSERT_EQUAL(string("default.domain"), c.domain);
|
||||
CPPUNIT_ASSERT_EQUAL(string("/default/path"), c.path);
|
||||
CPPUNIT_ASSERT_EQUAL(false, c.secure);
|
||||
CPPUNIT_ASSERT_EQUAL(true, c.onetime);
|
||||
|
||||
|
|
Loading…
Reference in New Issue