diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-10-26 14:22:58 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-10-26 14:22:58 +0000 |
| commit | 915aa676f8d980dcf2bf88154037b6df0edc3b58 (patch) | |
| tree | 1faf54d86f073268088855eade4e50f699b5a178 /src | |
| parent | 8a920ba5e38b8a7c43dc088b1837026e69b078f3 (diff) | |
2008-10-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Treat Cookie object as session cookie if expiry = 0 is given.
With this change, you can specify session scoped cookies in an
external file setting expiry value to 0.
* src/Cookie.cc
* src/Cookie.h
* test/CookieParserTest.cc
* test/CookieStorageTest.cc
* test/CookieTest.cc
Diffstat (limited to 'src')
| -rw-r--r-- | src/Cookie.cc | 20 | ||||
| -rw-r--r-- | src/Cookie.h | 16 |
2 files changed, 21 insertions, 15 deletions
diff --git a/src/Cookie.cc b/src/Cookie.cc index 9a771ae9..8caeca70 100644 --- a/src/Cookie.cc +++ b/src/Cookie.cc @@ -33,10 +33,12 @@ */ /* copyright --> */ #include "Cookie.h" + +#include <algorithm> + #include "Util.h" #include "A2STR.h" #include "TimeA2.h" -#include <algorithm> namespace aria2 { @@ -51,8 +53,7 @@ Cookie::Cookie(const std::string& name, _expiry(expiry), _path(path), _domain(Util::toLower(domain)), - _secure(secure), - _onetime(false) {} + _secure(secure) {} Cookie::Cookie(const std::string& name, const std::string& value, @@ -64,10 +65,9 @@ Cookie::Cookie(const std::string& name, _expiry(0), _path(path), _domain(Util::toLower(domain)), - _secure(secure), - _onetime(true) {} + _secure(secure) {} -Cookie::Cookie():_expiry(0), _secure(false), _onetime(true) {} +Cookie::Cookie():_expiry(0), _secure(false) {} Cookie::~Cookie() {} @@ -115,7 +115,7 @@ bool Cookie::match(const std::string& requestHost, if((secure || (!_secure && !secure)) && domainMatch(lowerRequestHost, _domain) && pathInclude(requestPath, _path) && - (_onetime || (date < _expiry))) { + (isSessionCookie() || (date < _expiry))) { return true; } else { return false; @@ -172,7 +172,7 @@ bool Cookie::operator==(const Cookie& cookie) const bool Cookie::isExpired() const { - return !_onetime && Time().getTime() >= _expiry; + return !_expiry == 0 && Time().getTime() >= _expiry; } const std::string& Cookie::getName() const @@ -205,9 +205,9 @@ bool Cookie::isSecureCookie() const return _secure; } -bool Cookie::isOnetimeCookie() const +bool Cookie::isSessionCookie() const { - return _onetime; + return _expiry == 0; } } // namespace aria2 diff --git a/src/Cookie.h b/src/Cookie.h index 9052a629..b1b98573 100644 --- a/src/Cookie.h +++ b/src/Cookie.h @@ -36,10 +36,12 @@ #define _D_COOKIE_H_ #include "common.h" -#include "a2time.h" + #include <string> #include <deque> +#include "a2time.h" + namespace aria2 { class Cookie { @@ -50,10 +52,10 @@ private: std::string _path; std::string _domain; bool _secure; - - // If true, this cookie will expire when aria2 exits. - bool _onetime; public: + /* + * If expires = 0 is given, then the cookie becomes session cookie. + */ Cookie(const std::string& name, const std::string& value, time_t expires, @@ -61,6 +63,10 @@ public: const std::string& domain, bool secure); + /* + * Creates session cookie. This is equivalent to + * Cookie(name, value, 0, path, domain, secure); + */ Cookie(const std::string& name, const std::string& value, const std::string& path, @@ -97,7 +103,7 @@ public: bool isSecureCookie() const; - bool isOnetimeCookie() const; + bool isSessionCookie() const; }; typedef std::deque<Cookie> Cookies; |
