Added support for a 'Priority' attribute on cookies.

This commit is contained in:
karlr42 2014-03-06 15:20:36 +00:00
parent 9f3abcbef7
commit e060f109fd
2 changed files with 37 additions and 2 deletions

View File

@ -139,10 +139,16 @@ public:
void setPath(const std::string& path);
/// Sets the path for the cookie.
void setPriority(const std::string& priority);
/// Sets the priority for the cookie.
const std::string& getPath() const;
/// Returns the path for the cookie.
const std::string& getPriority() const;
/// Returns the priority for the cookie.
void setSecure(bool secure);
/// Sets the value of the secure flag for
/// the cookie.
@ -210,6 +216,7 @@ private:
std::string _comment;
std::string _domain;
std::string _path;
std::string _priority;
bool _secure;
int _maxAge;
bool _httpOnly;
@ -254,6 +261,11 @@ inline const std::string& HTTPCookie::getPath() const
return _path;
}
inline const std::string& HTTPCookie::getPriority() const
{
return _priority;
}
inline bool HTTPCookie::getSecure() const
{

View File

@ -102,6 +102,10 @@ HTTPCookie::HTTPCookie(const NameValueCollection& nvc):
{
setPath(value);
}
else if (icompare(name, "Priority") == 0)
{
setPriority(value);
}
else if (icompare(name, "max-age") == 0)
{
setMaxAge(NumberParser::parse(value));
@ -115,7 +119,7 @@ HTTPCookie::HTTPCookie(const NameValueCollection& nvc):
int tzd;
DateTime exp = DateTimeParser::parse(value, tzd);
Timestamp now;
setMaxAge((int) ((exp.timestamp() - now) / Timestamp::resolution()));
setMaxAge((int) ((exp.timestamp() - now)/Timestamp::resolution()));
}
else if (icompare(name, "version") == 0)
{
@ -152,6 +156,7 @@ HTTPCookie::HTTPCookie(const HTTPCookie& cookie):
_comment(cookie._comment),
_domain(cookie._domain),
_path(cookie._path),
_priority(cookie._priority),
_secure(cookie._secure),
_maxAge(cookie._maxAge),
_httpOnly(cookie._httpOnly)
@ -174,6 +179,7 @@ HTTPCookie& HTTPCookie::operator = (const HTTPCookie& cookie)
_comment = cookie._comment;
_domain = cookie._domain;
_path = cookie._path;
_priority = cookie._priority;
_secure = cookie._secure;
_maxAge = cookie._maxAge;
_httpOnly = cookie._httpOnly;
@ -217,6 +223,11 @@ void HTTPCookie::setPath(const std::string& path)
_path = path;
}
void HTTPCookie::setPriority(const std::string& priority)
{
_priority = priority;
}
void HTTPCookie::setSecure(bool secure)
{
@ -256,10 +267,15 @@ std::string HTTPCookie::toString() const
result.append("; path=");
result.append(_path);
}
if (!_priority.empty())
{
result.append("; Priority=");
result.append(_priority);
}
if (_maxAge != -1)
{
Timestamp ts;
ts += _maxAge * Timestamp::resolution();
ts += _maxAge*Timestamp::resolution();
result.append("; expires=");
DateTimeFormatter::append(result, ts, DateTimeFormat::HTTP_FORMAT);
}
@ -296,6 +312,13 @@ std::string HTTPCookie::toString() const
result.append(_path);
result.append("\"");
}
if (!_priority.empty())
{
result.append("; Priority=\"");
result.append(_priority);
result.append("\"");
}
if (_maxAge != -1)
{
result.append("; Max-Age=\"");