mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-11 23:05:34 +08:00
refs #497, improved URL and network utils
* utility functions * URL, allow to switch to https * Adjusted database writer
This commit is contained in:
committed by
Mathew Sutcliffe
parent
03f4aa6889
commit
7cb4c6a6c6
@@ -181,5 +181,44 @@ namespace BlackMisc
|
||||
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
request.setSslConfiguration(conf);
|
||||
}
|
||||
|
||||
QHttpPart CNetworkUtils::getMultipartWithDebugFlag()
|
||||
{
|
||||
QHttpPart textPartDebug;
|
||||
textPartDebug.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"XDEBUG_SESSION_START\""));
|
||||
textPartDebug.setBody(QString("ECLIPSE_DBGP").toUtf8());
|
||||
return textPartDebug;
|
||||
}
|
||||
|
||||
void CNetworkUtils::addDebugFlag(QUrlQuery &qurl)
|
||||
{
|
||||
qurl.addQueryItem("XDEBUG_SESSION_START", "ECLIPSE_DBGP");
|
||||
}
|
||||
|
||||
QHttpPart CNetworkUtils::getJsonTextMutlipart(const QJsonObject &json)
|
||||
{
|
||||
const QByteArray jsonData(QJsonDocument(json).toJson(QJsonDocument::Compact));
|
||||
QHttpPart textPart;
|
||||
QString name("form-data; name=\"swiftjson\"");
|
||||
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(name));
|
||||
textPart.setBody(jsonData);
|
||||
return textPart;
|
||||
}
|
||||
|
||||
QNetworkRequest CNetworkUtils::getNetworkRequest(const CUrl &url, RequestType type)
|
||||
{
|
||||
QNetworkRequest request(url.toQUrl());
|
||||
switch (type)
|
||||
{
|
||||
case PostUrlEncoded:
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
CNetworkUtils::ignoreSslVerification(request);
|
||||
return request;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespacee
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
#include "blackmisc/network/server.h"
|
||||
#include "blackmisc/network/url.h"
|
||||
#include <QUrl>
|
||||
#include <QHttpPart>
|
||||
#include <QStringList>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkRequest>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -27,6 +30,15 @@ namespace BlackMisc
|
||||
class BLACKMISC_EXPORT CNetworkUtils
|
||||
{
|
||||
public:
|
||||
|
||||
//! Request type
|
||||
enum RequestType
|
||||
{
|
||||
Get,
|
||||
PostUrlEncoded,
|
||||
Multipart
|
||||
};
|
||||
|
||||
//! Is a connected interface available?
|
||||
//! \param withDebugOutput enables some debugging output
|
||||
//! \return
|
||||
@@ -74,6 +86,18 @@ namespace BlackMisc
|
||||
//! Ignore SSL verification such as self signed certificates
|
||||
static void ignoreSslVerification(QNetworkRequest &request);
|
||||
|
||||
//! Multipart with DEBUG FLAG for server
|
||||
static QHttpPart getMultipartWithDebugFlag();
|
||||
|
||||
//! Add debug flag
|
||||
static void addDebugFlag(QUrlQuery &qurl);
|
||||
|
||||
//! Multipart for JSON
|
||||
static QHttpPart getJsonTextMutlipart(const QJsonObject &json);
|
||||
|
||||
//! Our tweakes network request
|
||||
static QNetworkRequest getNetworkRequest(const CUrl &url, RequestType type = Get);
|
||||
|
||||
private:
|
||||
//! Deleted constructor
|
||||
CNetworkUtils() {}
|
||||
|
||||
@@ -100,7 +100,6 @@ namespace BlackMisc
|
||||
|
||||
QString CUrl::getFullUrl() const
|
||||
{
|
||||
Q_ASSERT_X(!m_host.isEmpty(), Q_FUNC_INFO, "missing address");
|
||||
if (m_host.isEmpty()) { return ""; }
|
||||
|
||||
QString qn(m_host);
|
||||
@@ -138,6 +137,16 @@ namespace BlackMisc
|
||||
return url;
|
||||
}
|
||||
|
||||
CUrl CUrl::withSwitchedScheme(const QString &scheme, int port) const
|
||||
{
|
||||
if (getPort() == port && getScheme() == scheme) { return *this; }
|
||||
QUrl qurl(this->toQUrl());
|
||||
qurl.setPort(port);
|
||||
qurl.setScheme(scheme);
|
||||
CUrl url(qurl);
|
||||
return url;
|
||||
}
|
||||
|
||||
CUrl CUrl::withAppendedQuery(const QString &query) const
|
||||
{
|
||||
if (query.isEmpty()) { return *this; }
|
||||
|
||||
@@ -119,6 +119,9 @@ namespace BlackMisc
|
||||
//! Append path
|
||||
CUrl withAppendedQuery(const QString &query) const;
|
||||
|
||||
//! Switch protocol
|
||||
CUrl withSwitchedScheme(const QString &protocol, int port) const;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user