mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 23:39:45 -05:00
Fix compilation errors with old versions of qt.
This commit is contained in:
parent
728acb77cf
commit
e5f7c46838
@ -1,15 +1,19 @@
|
|||||||
|
|
||||||
#include "NetworkRequest.h"
|
#include "NetworkRequest.h"
|
||||||
|
|
||||||
|
#ifdef WITH_XC_NETWORKING
|
||||||
|
|
||||||
#include "NetworkManager.h"
|
#include "NetworkManager.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QtNetwork/QNetworkAccessManager>
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
#include <QtNetwork/QNetworkReply>
|
#include <QtNetwork/QNetworkReply>
|
||||||
#include <QtNetwork/QNetworkRequest>
|
#include <QtNetwork/QNetworkRequest>
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
QList<QPair<QString, QString>> createDefaultHeaders() {
|
QList<QPair<QString, QString>> createDefaultHeaders() {
|
||||||
QList<QPair<QString, QString>> headers;
|
QList<QPair<QString, QString>> headers;
|
||||||
headers.append(QPair{"User-Agent", "KeePassXC"});
|
headers.append(QPair<QString, QString>("User-Agent", "KeePassXC"));
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,16 +39,16 @@ namespace
|
|||||||
QString contentType;
|
QString contentType;
|
||||||
QHash<QString, QString> contentTypeParameters;
|
QHash<QString, QString> contentTypeParameters;
|
||||||
// Parse content type
|
// Parse content type
|
||||||
auto tokens = contentTypeHeader.split(";", Qt::SkipEmptyParts);
|
auto tokens = contentTypeHeader.split(";", QString::SkipEmptyParts);
|
||||||
if(tokens.isEmpty()) {
|
if(tokens.isEmpty()) {
|
||||||
return {contentType, contentTypeParameters};
|
return qMakePair(contentType, contentTypeParameters);
|
||||||
}
|
}
|
||||||
contentType = tokens[0].trimmed();
|
contentType = tokens[0].trimmed();
|
||||||
for (int i = 1; i < tokens.size(); ++i) {
|
for (int i = 1; i < tokens.size(); ++i) {
|
||||||
auto parameterTokens = tokens[i].split("=");
|
auto parameterTokens = tokens[i].split("=");
|
||||||
contentTypeParameters[parameterTokens[0].trimmed()] = parameterTokens[1].trimmed();
|
contentTypeParameters[parameterTokens[0].trimmed()] = parameterTokens[1].trimmed();
|
||||||
}
|
}
|
||||||
return {contentType, contentTypeParameters};
|
return qMakePair(contentType, contentTypeParameters);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -252,7 +256,7 @@ NetworkRequestBuilder& NetworkRequestBuilder::setHeaders(QList<QPair<QString, QS
|
|||||||
if (std::none_of(m_headers.begin(), m_headers.end(), [](const auto& pair) {
|
if (std::none_of(m_headers.begin(), m_headers.end(), [](const auto& pair) {
|
||||||
return pair.first == "User-Agent";
|
return pair.first == "User-Agent";
|
||||||
})) {
|
})) {
|
||||||
m_headers.append(QPair{"User-Agent", "KeePassXC"});
|
m_headers.append(QPair<QString, QString>("User-Agent", "KeePassXC"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -288,3 +292,5 @@ NetworkRequestBuilder& NetworkRequestBuilder::setMaxRedirects(unsigned int maxRe
|
|||||||
m_maxRedirects = maxRedirects;
|
m_maxRedirects = maxRedirects;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -17,6 +17,10 @@
|
|||||||
#ifndef KEEPASSXC_NETWORKREQUEST_H
|
#ifndef KEEPASSXC_NETWORKREQUEST_H
|
||||||
#define KEEPASSXC_NETWORKREQUEST_H
|
#define KEEPASSXC_NETWORKREQUEST_H
|
||||||
|
|
||||||
|
#include "config-keepassx.h"
|
||||||
|
|
||||||
|
#ifdef WITH_XC_NETWORKING
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@ -157,4 +161,6 @@ public:
|
|||||||
NetworkRequest build();
|
NetworkRequest build();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // KEEPASSXC_NETWORKREQUEST_H
|
#endif // KEEPASSXC_NETWORKREQUEST_H
|
||||||
|
@ -12,7 +12,7 @@ using ContentTypeParameters_t = QHash<QString, QString>;
|
|||||||
Q_DECLARE_METATYPE(ContentTypeParameters_t);
|
Q_DECLARE_METATYPE(ContentTypeParameters_t);
|
||||||
Q_DECLARE_METATYPE(std::chrono::milliseconds);
|
Q_DECLARE_METATYPE(std::chrono::milliseconds);
|
||||||
|
|
||||||
static constexpr auto TIMEOUT_GRACE_MS = 25;
|
static constexpr auto TIMEOUT_GRACE_MS = 100;
|
||||||
|
|
||||||
void TestNetworkRequest::testNetworkRequest()
|
void TestNetworkRequest::testNetworkRequest()
|
||||||
{
|
{
|
||||||
@ -45,13 +45,13 @@ void TestNetworkRequest::testNetworkRequest()
|
|||||||
// Create request
|
// Create request
|
||||||
NetworkRequest request = buildRequest(requestedURL).setManager(&manager).build();
|
NetworkRequest request = buildRequest(requestedURL).setManager(&manager).build();
|
||||||
|
|
||||||
QString actualContent;
|
QByteArray actualContent;
|
||||||
bool didError = false, didSucceed = false;
|
bool didError = false, didSucceed = false;
|
||||||
|
|
||||||
// Check request
|
// Check request
|
||||||
QSignalSpy spy(&request, &NetworkRequest::success);
|
QSignalSpy spy(&request, &NetworkRequest::success);
|
||||||
connect(&request, &NetworkRequest::success, [&actualContent, &didSucceed](QByteArray content) {
|
connect(&request, &NetworkRequest::success, [&actualContent, &didSucceed](QByteArray content) {
|
||||||
actualContent = QString(content);
|
actualContent = content;
|
||||||
didSucceed = true;
|
didSucceed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user