mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 21:46:03 +03:00
Put cookies into csync
We already have the auth cookies from the quota request, so put them into csync to avoid a 401 roundtrip
This commit is contained in:
parent
ab72644ace
commit
ab7bfabf12
5 changed files with 34 additions and 0 deletions
|
@ -320,6 +320,19 @@ void CSyncThread::startSync()
|
|||
csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx);
|
||||
csync_set_userdata(_csync_ctx, this);
|
||||
|
||||
if (_lastAuthCookies.length() > 0) {
|
||||
// Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply
|
||||
// when https://github.com/owncloud/core/pull/4042 is merged.
|
||||
QString cookiesAsString;
|
||||
foreach(QNetworkCookie c, _lastAuthCookies) {
|
||||
cookiesAsString += c.name();
|
||||
cookiesAsString += '=';
|
||||
cookiesAsString += c.value();
|
||||
cookiesAsString += "; ";
|
||||
}
|
||||
csync_set_module_property(_csync_ctx, "session_key", cookiesAsString.toAscii().data());
|
||||
}
|
||||
|
||||
// csync_set_auth_callback( _csync_ctx, getauth );
|
||||
|
||||
qDebug() << "#### Update start #################################################### >>";
|
||||
|
@ -395,5 +408,10 @@ void CSyncThread::cb_progress(const char *remote_url, enum csync_notify_type_e k
|
|||
}
|
||||
}
|
||||
|
||||
void CSyncThread::setLastAuthCookies(QList<QNetworkCookie> c)
|
||||
{
|
||||
_lastAuthCookies = c;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QThread>
|
||||
#include <QString>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkCookie>
|
||||
|
||||
#include <csync.h>
|
||||
|
||||
|
@ -43,6 +44,8 @@ public:
|
|||
|
||||
Q_INVOKABLE void startSync();
|
||||
|
||||
void setLastAuthCookies(QList<QNetworkCookie> c);
|
||||
|
||||
signals:
|
||||
void fileReceived( const QString& );
|
||||
void fileRemoved( const QString& );
|
||||
|
@ -86,6 +89,8 @@ private:
|
|||
|
||||
bool _hasFiles; // true if there is at least one file that is not ignored or removed
|
||||
|
||||
QList<QNetworkCookie> _lastAuthCookies;
|
||||
|
||||
friend class CSyncRunScopeHelper;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -298,8 +298,10 @@ void ownCloudFolder::startSync(const QStringList &pathList)
|
|||
_thread->setPriority(QThread::LowPriority);
|
||||
setIgnoredFiles();
|
||||
_csync = new CSyncThread( _csync_ctx );
|
||||
_csync->setLastAuthCookies(ownCloudInfo::instance()->getLastAuthCookies());
|
||||
_csync->moveToThread(_thread);
|
||||
|
||||
|
||||
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
|
||||
qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction");
|
||||
|
||||
|
|
|
@ -373,6 +373,13 @@ void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *aut
|
|||
}
|
||||
}
|
||||
|
||||
QList<QNetworkCookie> ownCloudInfo::getLastAuthCookies()
|
||||
{
|
||||
QUrl url = QUrl( webdavUrl(_connection));
|
||||
QList<QNetworkCookie> cookies = _manager->cookieJar()->cookiesForUrl(url);
|
||||
return cookies;
|
||||
}
|
||||
|
||||
QString ownCloudInfo::configHandle(QNetworkReply *reply)
|
||||
{
|
||||
QString configHandle;
|
||||
|
|
|
@ -118,6 +118,8 @@ public:
|
|||
qint64 lastQuotaUsedBytes() const { return _lastQuotaUsedBytes; }
|
||||
qint64 lastQuotaTotalBytes() const { return _lastQuotaTotalBytes; }
|
||||
|
||||
QList<QNetworkCookie> getLastAuthCookies();
|
||||
|
||||
signals:
|
||||
// result signal with url- and version string.
|
||||
void ownCloudInfoFound( const QString&, const QString&, const QString&, const QString& );
|
||||
|
|
Loading…
Reference in a new issue