mirror of https://github.com/aria2/aria2
2010-01-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed parse(std::istream&) and parse(const std::string&) from CookieParser. * src/CookieParser.cc * src/CookieParser.h * test/CookieParserTest.cc * test/cookietest.txt: Removedpull/1/head
parent
58f51205c6
commit
100ad4e18a
|
@ -1,3 +1,12 @@
|
||||||
|
2010-01-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Removed parse(std::istream&) and parse(const std::string&) from
|
||||||
|
CookieParser.
|
||||||
|
* src/CookieParser.cc
|
||||||
|
* src/CookieParser.h
|
||||||
|
* test/CookieParserTest.cc
|
||||||
|
* test/cookietest.txt: Removed
|
||||||
|
|
||||||
2010-01-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-01-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Fixed the bug that cookie for domain a.b.c is not sent to the host
|
Fixed the bug that cookie for domain a.b.c is not sent to the host
|
||||||
|
|
|
@ -55,11 +55,6 @@ const std::string CookieParser::C_PATH("path");
|
||||||
|
|
||||||
const std::string CookieParser::C_EXPIRES("expires");
|
const std::string CookieParser::C_EXPIRES("expires");
|
||||||
|
|
||||||
Cookie CookieParser::parse(const std::string& cookieStr) const
|
|
||||||
{
|
|
||||||
return parse(cookieStr, A2STR::NIL, A2STR::NIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defaultDomain, const std::string& defaultPath) const
|
Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defaultDomain, const std::string& defaultPath) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> terms;
|
std::vector<std::string> terms;
|
||||||
|
@ -105,21 +100,4 @@ Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defa
|
||||||
return cookie;
|
return cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Cookies CookieParser::parse(std::istream& s) const
|
|
||||||
{
|
|
||||||
Cookies cookies;
|
|
||||||
std::string line;
|
|
||||||
while(getline(s, line)) {
|
|
||||||
if(util::trim(line).empty() || util::startsWith(line, A2STR::SHARP_C)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Cookie cookie = parse(line);
|
|
||||||
if(cookie.good()) {
|
|
||||||
cookies.push_back(cookie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -36,26 +36,18 @@
|
||||||
#define _D_COOKIE_PARSER_H_
|
#define _D_COOKIE_PARSER_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "Cookie.h"
|
#include "Cookie.h"
|
||||||
#include <string>
|
|
||||||
#include <iosfwd>
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class CookieParser {
|
class CookieParser {
|
||||||
public:
|
public:
|
||||||
CookieParser() {}
|
|
||||||
|
|
||||||
~CookieParser() {}
|
|
||||||
|
|
||||||
Cookie parse(const std::string& cookieStr, const std::string& defaultDomain,
|
Cookie parse(const std::string& cookieStr, const std::string& defaultDomain,
|
||||||
const std::string& defaultPath) const;
|
const std::string& defaultPath) const;
|
||||||
|
|
||||||
Cookie parse(const std::string& cookieStr) const;
|
|
||||||
|
|
||||||
Cookies parse(std::istream& s) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const std::string C_SECURE;
|
static const std::string C_SECURE;
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,15 @@
|
||||||
#include "CookieParser.h"
|
#include "CookieParser.h"
|
||||||
#include <fstream>
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class CookieParserTest:public CppUnit::TestFixture {
|
class CookieParserTest:public CppUnit::TestFixture {
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(CookieParserTest);
|
CPPUNIT_TEST_SUITE(CookieParserTest);
|
||||||
CPPUNIT_TEST(testParse);
|
CPPUNIT_TEST(testParse);
|
||||||
CPPUNIT_TEST(testParse_file);
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setUp() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void testParse();
|
void testParse();
|
||||||
|
|
||||||
void testParse_file();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +18,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( CookieParserTest );
|
||||||
void CookieParserTest::testParse()
|
void CookieParserTest::testParse()
|
||||||
{
|
{
|
||||||
std::string str = "JSESSIONID=123456789; expires=Sun, 10-Jun-2007 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);
|
Cookie c = CookieParser().parse(str, "", "");
|
||||||
CPPUNIT_ASSERT(c.good());
|
CPPUNIT_ASSERT(c.good());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
|
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
|
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
|
||||||
|
@ -49,7 +40,7 @@ void CookieParserTest::testParse()
|
||||||
CPPUNIT_ASSERT_EQUAL(true, c.isSessionCookie());
|
CPPUNIT_ASSERT_EQUAL(true, c.isSessionCookie());
|
||||||
|
|
||||||
std::string str3 = "";
|
std::string str3 = "";
|
||||||
c = CookieParser().parse(str3);
|
c = CookieParser().parse(str3, "", "");
|
||||||
CPPUNIT_ASSERT(!c.good());
|
CPPUNIT_ASSERT(!c.good());
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
|
@ -65,7 +56,7 @@ void CookieParserTest::testParse()
|
||||||
CPPUNIT_ASSERT_EQUAL(expire_time, c.getExpiry());
|
CPPUNIT_ASSERT_EQUAL(expire_time, c.getExpiry());
|
||||||
|
|
||||||
std::string str5 = "k=v; expires=Sun, 10-Jun-07 11:00:00 GMT";
|
std::string str5 = "k=v; expires=Sun, 10-Jun-07 11:00:00 GMT";
|
||||||
c = CookieParser().parse(str5);
|
c = CookieParser().parse(str5, "", "");
|
||||||
CPPUNIT_ASSERT(c.good());
|
CPPUNIT_ASSERT(c.good());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("k"), c.getName());
|
CPPUNIT_ASSERT_EQUAL(std::string("k"), c.getName());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("v"), c.getValue());
|
CPPUNIT_ASSERT_EQUAL(std::string("v"), c.getValue());
|
||||||
|
@ -76,25 +67,4 @@ void CookieParserTest::testParse()
|
||||||
CPPUNIT_ASSERT(!c.isSessionCookie());
|
CPPUNIT_ASSERT(!c.isSessionCookie());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CookieParserTest::testParse_file()
|
|
||||||
{
|
|
||||||
std::ifstream f("cookietest.txt", std::ios::binary);
|
|
||||||
|
|
||||||
Cookies cookies = CookieParser().parse(f);
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((int32_t)3, (int32_t)cookies.size());
|
|
||||||
|
|
||||||
Cookie c = cookies[0];
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
|
|
||||||
|
|
||||||
c = cookies[1];
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("user"), c.getName());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("me"), c.getValue());
|
|
||||||
|
|
||||||
c = cookies[2];
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
JSESSIONID=123456789; expires=Sun, 2007-06-10 11:00:00 GMT; path=/; domain=localhost; secure
|
|
||||||
# name=this is a omment line;
|
|
||||||
|
|
||||||
user=me;
|
|
||||||
|
|
||||||
passwd=secret
|
|
Loading…
Reference in New Issue