Skip to content

Commit b01f807

Browse files
authored
fix: cleanup the cookie jar (#12243)
And make it clear why this class exists: so we can clone it for cases where we don't want to spoil the original jar.
1 parent 3a8ff73 commit b01f807

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/libsync/cookiejar.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// todo: #31
1818

1919
#include <QLoggingCategory>
20+
#include <QNetworkCookie>
2021

2122
namespace OCC {
2223

@@ -31,4 +32,11 @@ CookieJar::~CookieJar()
3132
{
3233
}
3334

35+
CookieJar *CookieJar::clone(QObject *parent)
36+
{
37+
auto newJar = new CookieJar(parent);
38+
newJar->setAllCookies(allCookies());
39+
return newJar;
40+
}
41+
3442
} // namespace OCC

src/libsync/cookiejar.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace OCC {
2323

2424
/**
25-
* @brief The CookieJar class
25+
* @brief A clonable cookie jar. This can be used when we don't want to spoil the original cookie jar.
2626
* @ingroup libsync
2727
*/
2828
class OWNCLOUDSYNC_EXPORT CookieJar : public QNetworkCookieJar
@@ -32,8 +32,10 @@ class OWNCLOUDSYNC_EXPORT CookieJar : public QNetworkCookieJar
3232
explicit CookieJar(QObject *parent = nullptr);
3333
~CookieJar() override;
3434

35-
using QNetworkCookieJar::setAllCookies;
36-
using QNetworkCookieJar::allCookies;
35+
/**
36+
* Return a clone of this cookie jar, with a copy of all cookies.
37+
*/
38+
CookieJar *clone(QObject *parent = nullptr);
3739
};
3840

3941
} // namespace OCC

src/libsync/networkjobs/checkserverjobfactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ CheckServerJobFactory CheckServerJobFactory::createFromAccount(const AccountPtr
7676
nam->setParent(parent);
7777
// do we start with the old cookies or new
7878
if (!(clearCookies && Theme::instance()->connectionValidatorClearCookies())) {
79-
const auto accountCookies = account->accessManager()->ownCloudCookieJar()->allCookies();
80-
nam->ownCloudCookieJar()->setAllCookies(accountCookies);
79+
const auto newJar = account->accessManager()->ownCloudCookieJar()->clone();
80+
nam->setCookieJar(newJar);
8181
}
8282
return CheckServerJobFactory(nam);
8383
}

0 commit comments

Comments
 (0)