Account: Send a X-Request-ID header #5853

This commit is contained in:
Christian Kamm 2017-07-13 10:53:16 +02:00 committed by Markus Goetz
parent 5738110cb6
commit 1c2d5f16c8
2 changed files with 17 additions and 0 deletions

View file

@ -33,6 +33,8 @@
#include <QDir> #include <QDir>
#include <QSslKey> #include <QSslKey>
#include <QUuid>
namespace OCC { namespace OCC {
Q_LOGGING_CATEGORY(lcAccount, "sync.account", QtInfoMsg) Q_LOGGING_CATEGORY(lcAccount, "sync.account", QtInfoMsg)
@ -123,6 +125,13 @@ AbstractCredentials *Account::credentials() const
return _credentials.data(); 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) void Account::setCredentials(AbstractCredentials *cred)
{ {
// set active credential manager // set active credential manager
@ -155,6 +164,10 @@ void Account::setCredentials(AbstractCredentials *cred)
SLOT(slotCredentialsFetched())); SLOT(slotCredentialsFetched()));
connect(_credentials.data(), SIGNAL(asked()), connect(_credentials.data(), SIGNAL(asked()),
SLOT(slotCredentialsAsked())); SLOT(slotCredentialsAsked()));
// Generate a new request id
_requestId = generateRequestId();
qCInfo(lcAccount) << "Account for" << url() << "has X-Request-ID" << _requestId;
} }
QUrl Account::davUrl() const QUrl Account::davUrl() const
@ -230,6 +243,7 @@ QNetworkReply *Account::sendRequest(const QByteArray &verb, const QUrl &url, QNe
{ {
req.setUrl(url); req.setUrl(url);
req.setSslConfiguration(this->getOrCreateSslConfig()); req.setSslConfiguration(this->getOrCreateSslConfig());
req.setRawHeader("X-Request-ID", _requestId);
if (verb == "HEAD" && !data) { if (verb == "HEAD" && !data) {
return _am->head(req); return _am->head(req);
} else if (verb == "GET" && !data) { } else if (verb == "GET" && !data) {

View file

@ -251,6 +251,9 @@ private:
/// Certificates that were explicitly rejected by the user /// Certificates that were explicitly rejected by the user
QList<QSslCertificate> _rejectedCertificates; QList<QSslCertificate> _rejectedCertificates;
/// X-Request-ID to send in network requests
QByteArray _requestId;
static QString _configFileName; static QString _configFileName;
QString _davPath; // defaults to value from theme, might be overwritten in brandings QString _davPath; // defaults to value from theme, might be overwritten in brandings