Account: Send a X-Request-ID header #5853
authorChristian Kamm <mail@ckamm.de>
Thu, 13 Jul 2017 08:53:16 +0000 (10:53 +0200)
committerMarkus Goetz <markus@woboq.com>
Thu, 13 Jul 2017 16:06:40 +0000 (18:06 +0200)
src/libsync/account.cpp
src/libsync/account.h

index 45168033f647c5679001874025e90b96c62632d1..2d798c0ec374a6fcd93aa6529986adff43c860d4 100644 (file)
@@ -33,6 +33,8 @@
 #include <QDir>
 #include <QSslKey>
 
+#include <QUuid>
+
 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) {
index b34342d4525b4180de42b3deb5bb219f7b5f667e..9fdc79ac9609416aefa42b62f6464e2754c8385e 100644 (file)
@@ -251,6 +251,9 @@ private:
     /// Certificates that were explicitly rejected by the user
     QList<QSslCertificate> _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