mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
refs #930, moved multipart functions to database utils and added support for compression
This commit is contained in:
committed by
Mathew Sutcliffe
parent
03cbdcddc2
commit
660798e43c
@@ -306,5 +306,50 @@ namespace BlackCore
|
||||
{
|
||||
return sApp && sApp->hasWebDataServices() && sApp->getWebDataServices()->hasDbAircraftData();
|
||||
}
|
||||
|
||||
const QUrlQuery &CDatabaseUtils::getCompressedQuery()
|
||||
{
|
||||
static const QUrlQuery q("compressed=true");
|
||||
return q;
|
||||
}
|
||||
|
||||
QHttpPart CDatabaseUtils::getJsonTextMultipart(const QJsonObject &json, bool compress)
|
||||
{
|
||||
const QByteArray bytes(QJsonDocument(json).toJson(QJsonDocument::Compact));
|
||||
return getJsonTextMultipart(bytes, compress);
|
||||
}
|
||||
|
||||
QHttpPart CDatabaseUtils::getJsonTextMultipart(const QJsonArray &json, bool compress)
|
||||
{
|
||||
const QByteArray bytes(QJsonDocument(json).toJson(QJsonDocument::Compact));
|
||||
return getJsonTextMultipart(bytes, compress);
|
||||
}
|
||||
|
||||
QHttpPart CDatabaseUtils::getJsonTextMultipart(const QByteArray &bytes, bool compress)
|
||||
{
|
||||
static const QString name("form-data; name=\"swiftjson\"");
|
||||
static const QVariant header(name);
|
||||
QHttpPart textPart;
|
||||
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, header);
|
||||
if (compress)
|
||||
{
|
||||
QByteArray ba = qCompress(bytes);
|
||||
ba.remove(0, 4); // remove the non standard header
|
||||
textPart.setBody(ba);
|
||||
}
|
||||
else
|
||||
{
|
||||
textPart.setBody(bytes);
|
||||
}
|
||||
return textPart;
|
||||
}
|
||||
|
||||
QHttpPart CDatabaseUtils::getMultipartWithDebugFlag()
|
||||
{
|
||||
QHttpPart textPartDebug;
|
||||
textPartDebug.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"XDEBUG_SESSION_START\""));
|
||||
textPartDebug.setBody(QString("ECLIPSE_DBGP").toUtf8());
|
||||
return textPartDebug;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackcore/progress.h"
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
#include <QHttpPart>
|
||||
#include <QUrlQuery>
|
||||
#include <QByteArray>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
@@ -69,6 +74,21 @@ namespace BlackCore
|
||||
|
||||
//! Convenience function
|
||||
static bool hasDbAircraftData();
|
||||
|
||||
//! Mark as compressed
|
||||
static const QUrlQuery &getCompressedQuery();
|
||||
|
||||
//! Multipart for JSON
|
||||
static QHttpPart getJsonTextMultipart(const QJsonObject &json, bool compress);
|
||||
|
||||
//! Multipart for JSON
|
||||
static QHttpPart getJsonTextMultipart(const QJsonArray &json, bool compress);
|
||||
|
||||
//! Multipart for JSON
|
||||
static QHttpPart getJsonTextMultipart(const QByteArray &bytes, bool compress);
|
||||
|
||||
//! Multipart with DEBUG FLAG for server
|
||||
static QHttpPart getMultipartWithDebugFlag();
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user