From: Christian Kamm Date: Thu, 13 Jul 2017 08:53:16 +0000 (+0200) Subject: Account: Send a X-Request-ID header #5853 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~704^2^2~32 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1c2d5f16c86657f6a03583e02e168810c1e3746f;p=nextcloud-desktop.git Account: Send a X-Request-ID header #5853 --- 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