12#include <QNetworkCookie>
16#include <QtConcurrentRun>
23 : QNetworkCookieJar (parent)
29 FilterTrackingCookies_ =
filter;
75 for (
const auto&
ba : data.split (
'\n'))
76 cookies << QNetworkCookie::parseCookies (
ba);
78 const auto&
now = QDateTime::currentDateTime ();
81 if (FilterTrackingCookies_ &&
82 cookie.name ().startsWith (
"__utm"))
98 const auto&
now = QDateTime::currentDateTime ();
119 for (
const auto&
cookie : QNetworkCookieJar::cookiesForUrl (
url))
131 return s.startsWith (
'.') ?
s.midRef (1) :
QStringRef { &
s };
145 return std::any_of (list.begin (), list.end (),
146 [&
str] (
const auto&
rx) { return str == rx.pattern () || rx.exactMatch (str); });
157 return std::make_tuple (
c.isHttpOnly (),
159 c.isSessionCookie (),
164 c.expirationDate ());
178 using Set_t = std::set<QNetworkCookie, CookieLess>;
185 std::back_inserter (
diff.Removed_),
189 std::back_inserter (
diff.Added_),
204 if (
cookie.domain ().isEmpty ())
220 if (FilterTrackingCookies_ &&
221 cookie.name ().startsWith (
"__utm"))
236 [
this] (
const CookiesDiff&
diff)
238 if (!
diff.Removed_.isEmpty ())
240 if (!
diff.Added_.isEmpty ())
244 return QNetworkCookieJar::setCookiesFromUrl (
filtered,
url);
void SetBlacklist(const QList< QRegExp > &list)
Sets the cookies blacklist.
void SetFilterTrackingCookies(bool filter)
void SetWhitelist(const QList< QRegExp > &list)
Sets the cookies whitelist.
void SetEnabled(bool enabled)
Enables or disables the cookies.
void SetExactDomainMatch(bool enabled)
Sets whether exact domain matching is enabled.
void cookiesRemoved(const QList< QNetworkCookie > &)
bool setCookiesFromUrl(const QList< QNetworkCookie > &cookieList, const QUrl &url) override
Adds the cookieList for the given url to the jar.
void Load(const QByteArray &data)
QList< QNetworkCookie > cookiesForUrl(const QUrl &url) const override
Returns cookies for the given url.
void cookiesAdded(const QList< QNetworkCookie > &)
CustomCookieJar(QObject *parent=nullptr)
Constructs the cookie jar.
QList< QNetworkCookie > Added_
QList< QNetworkCookie > Removed_
Container< T > Filter(const Container< T > &c, F f)
detail::ScopeGuard< F > MakeScopeGuard(const F &f)
Returns an object performing passed function on scope exit.