12#include <QNetworkCookie>
15#include <QtConcurrentRun>
22 : QNetworkCookieJar (parent)
28 FilterTrackingCookies_ =
filter;
74 for (
const auto&
ba : data.split (
'\n'))
75 cookies << QNetworkCookie::parseCookies (
ba);
77 const auto&
now = QDateTime::currentDateTime ();
80 if (FilterTrackingCookies_ &&
81 cookie.name ().startsWith (
"__utm"))
97 const auto&
now = QDateTime::currentDateTime ();
118 for (
const auto&
cookie : QNetworkCookieJar::cookiesForUrl (
url))
130 return s.startsWith (
'.') ?
s.mid (1) :
s;
144 return std::any_of (list.begin (), list.end (),
145 [&
str] (
const auto&
rx) { return str == rx.pattern () || rx.exactMatch (str); });
156 return std::make_tuple (
c.isHttpOnly (),
158 c.isSessionCookie (),
163 c.expirationDate ());
177 using Set_t = std::set<QNetworkCookie, CookieLess>;
184 std::back_inserter (
diff.Removed_),
188 std::back_inserter (
diff.Added_),
203 if (
cookie.domain ().isEmpty ())
219 if (FilterTrackingCookies_ &&
220 cookie.name ().startsWith (
"__utm"))
235 [
this] (
const CookiesDiff&
diff)
237 if (!
diff.Removed_.isEmpty ())
239 if (!
diff.Added_.isEmpty ())
243 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.