diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 45168033f..2d798c0ec 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -33,6 +33,8 @@ #include #include +#include + namespace OCC { Q_LOGGING_CATEGORY(lcAccount, "sync.account", QtInfoMsg) @@ -123,6 +125,13 @@ AbstractCredentials *Account::credentials() const return _credentials.data(); } +static QByteArray generateRequestId() +{ + // Use a UUID with the starting and ending curly brace removed. + auto uuid = QUuid::createUuid().toByteArray(); + return uuid.mid(1, uuid.size() - 2); +} + void Account::setCredentials(AbstractCredentials *cred) { // set active credential manager @@ -155,6 +164,10 @@ void Account::setCredentials(AbstractCredentials *cred) SLOT(slotCredentialsFetched())); connect(_credentials.data(), SIGNAL(asked()), SLOT(slotCredentialsAsked())); + + // Generate a new request id + _requestId = generateRequestId(); + qCInfo(lcAccount) << "Account for" << url() << "has X-Request-ID" << _requestId; } QUrl Account::davUrl() const @@ -230,6 +243,7 @@ QNetworkReply *Account::sendRequest(const QByteArray &verb, const QUrl &url, QNe { req.setUrl(url); req.setSslConfiguration(this->getOrCreateSslConfig()); + req.setRawHeader("X-Request-ID", _requestId); if (verb == "HEAD" && !data) { return _am->head(req); } else if (verb == "GET" && !data) { diff --git a/src/libsync/account.h b/src/libsync/account.h index b34342d45..9fdc79ac9 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -251,6 +251,9 @@ private: /// Certificates that were explicitly rejected by the user QList _rejectedCertificates; + /// X-Request-ID to send in network requests + QByteArray _requestId; + static QString _configFileName; QString _davPath; // defaults to value from theme, might be overwritten in brandings