35namespace network_manager
40 const size_t equalsPosition = cookieString.find (
'=');
43 return { cookieString, std::string () };
45 std::string
name = cookieString.substr (0, equalsPosition);
47 const size_t firstValueIndex = equalsPosition + 1;
49 const size_t semicolonPosition = cookieString.find (
';', firstValueIndex);
55 cookieString.substr (firstValueIndex) :
56 cookieString.substr (firstValueIndex, semicolonPosition - firstValueIndex);
58 size_t expiresPosition = cookieString.find(
"Expires=");
62 expiresPosition += std::strlen (
"Expires=");
64 const size_t trailingSemicolon = cookieString.find (
';', expiresPosition);
66 std::string expiresValue =
68 cookieString.substr (expiresPosition) :
69 cookieString.substr (expiresPosition, trailingSemicolon - expiresPosition);
72 std::replace (expiresValue.begin(), expiresValue.end(),
'-',
' ');
86 std::ostringstream stream;
102 std::chrono::system_clock::now() >=
Expires;
115 item->
Value = std::move (cookieValue);
117 mCookies.push_back ({ cookieName, std::move (cookieValue) });
127 mCookies.push_back ({ std::move (cookieName), std::move (cookieValue) });
132 return getCookie (cookieName) !=
nullptr;
147 return const_cast<CookiesList*
>(
this)->getCookie(idx);
166 if (!result.empty ())
167 result.push_back (
';');
169 result += cookie.Name +
"=" + cookie.Value;
197 if (idx < mCookies.size ())
198 return &mCookies[idx];
205 for (
Cookie& cookie : mCookies)
207 if (cookie.Name == cookieName)
Define HTTP cookies list class.
Declare functions to work with date and time string representations.
void setCookie(const Cookie &cookie)
std::string getCookieValue(const std::string &cookieName) const
CookiesStorageType::const_iterator CookiesConstIterator
void addCookie(Cookie cookie)
bool hasCookie(const std::string &cookieName) const noexcept
CookiesStorageType::iterator CookiesIterator
CookiesIterator begin() noexcept
CookiesStorageType mCookies
CookiesIterator end() noexcept
std::string getCookiesString() const
size_t getCookiesCount() const noexcept
const Cookie * getCookie(size_t idx) const noexcept
constexpr size_t npos(-1)
std::chrono::system_clock::time_point ExpiresTime
bool ParseRFC822Date(const std::string &dateString, SystemTime *time)
std::string SerializeRFC822Date(SystemTime timePoint)
bool isSession() const noexcept
static Cookie Parse(const std::string &cookieString)
bool isExpired() const noexcept
std::string toString(bool fullString) const