forked from loafle/openapi-generator-original
[C++] [Qt5]Add support for response compression and add response body to error s… (#5060)
* Add support for response compression and add response body to error string * Improve robustness while parsing quality and compression levels
This commit is contained in:
parent
ff7203875f
commit
a1d21f6d3a
@ -6,6 +6,7 @@ sidebar_label: cpp-qt5-client
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
||||
|contentCompression|Enable Compressed Content Encoding for requests and responses| |false|
|
||||
|cppNamespace|C++ namespace (convention: name::space::for::api).| |OpenAPI|
|
||||
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||
|modelNamePrefix|Prefix that will be prepended to all model names.| |OAI|
|
||||
|
@ -6,6 +6,7 @@ sidebar_label: cpp-qt5-qhttpengine-server
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
||||
|contentCompression|Enable Compressed Content Encoding for requests and responses| |false|
|
||||
|cppNamespace|C++ namespace (convention: name::space::for::api).| |OpenAPI|
|
||||
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||
|modelNamePrefix|Prefix that will be prepended to all model names.| |OAI|
|
||||
|
@ -21,10 +21,13 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected static final String CPP_NAMESPACE = "cppNamespace";
|
||||
protected static final String CPP_NAMESPACE_DESC = "C++ namespace (convention: name::space::for::api).";
|
||||
protected static final String CONTENT_COMPRESSION_ENABLED = "contentCompression";
|
||||
protected static final String CONTENT_COMPRESSION_ENABLED_DESC = "Enable Compressed Content Encoding for requests and responses";
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
protected String cppNamespace = "OpenAPI";
|
||||
protected Map<String, String> namespaces = new HashMap<String, String>();
|
||||
protected Set<String> systemIncludes = new HashSet<String>();
|
||||
protected boolean isContentCompressionEnabled = false;
|
||||
|
||||
protected Set<String> nonFrameworkPrimitives = new HashSet<String>();
|
||||
|
||||
@ -56,6 +59,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
// CLI options
|
||||
addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace);
|
||||
addOption(CodegenConstants.MODEL_NAME_PREFIX, CodegenConstants.MODEL_NAME_PREFIX_DESC, this.modelNamePrefix);
|
||||
addSwitch(CONTENT_COMPRESSION_ENABLED, CONTENT_COMPRESSION_ENABLED_DESC, this.isContentCompressionEnabled);
|
||||
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
@ -137,6 +141,11 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
typeMapping.put("object", modelNamePrefix + "Object");
|
||||
additionalProperties().put("prefix", modelNamePrefix);
|
||||
}
|
||||
if (additionalProperties.containsKey(CONTENT_COMPRESSION_ENABLED)) {
|
||||
setContentCompressionEnabled(convertPropertyToBooleanAndWriteBack(CONTENT_COMPRESSION_ENABLED));
|
||||
} else {
|
||||
additionalProperties.put(CONTENT_COMPRESSION_ENABLED, isContentCompressionEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -379,4 +388,8 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
}
|
||||
return included;
|
||||
}
|
||||
|
||||
public void setContentCompressionEnabled(boolean flag) {
|
||||
this.isContentCompressionEnabled = flag;
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,15 @@ set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wno-unused-variable")
|
||||
|
||||
find_package(Qt5Core REQUIRED)
|
||||
find_package(Qt5Network REQUIRED)
|
||||
find_package(Qt5Network REQUIRED){{#contentCompression}}
|
||||
find_package(ZLIB REQUIRED){{/contentCompression}}
|
||||
|
||||
file(GLOB SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} ${SRCS})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network ssl crypto)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network ssl crypto{{#contentCompression}} ${ZLIB_LIBRARIES}{{/contentCompression}})
|
||||
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
|
@ -6,7 +6,8 @@
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
#include <QtGlobal>
|
||||
#include <QtGlobal>{{#contentCompression}}
|
||||
#include <zlib.h>{{/contentCompression}}
|
||||
|
||||
#include "{{prefix}}HttpRequest.h"
|
||||
|
||||
@ -95,6 +96,10 @@ void {{prefix}}HttpRequestWorker::setWorkingDirectory(const QString &path) {
|
||||
}
|
||||
}
|
||||
|
||||
void {{prefix}}HttpRequestWorker::setCompressionEnabled(bool enable) {
|
||||
isCompressionEnabled = enable;
|
||||
}
|
||||
|
||||
QString {{prefix}}HttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
|
||||
// result structure follows RFC 5987
|
||||
bool need_utf_encoding = false;
|
||||
@ -303,6 +308,10 @@ void {{prefix}}HttpRequestWorker::execute({{prefix}}HttpRequestInput *input) {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary);
|
||||
}
|
||||
|
||||
if(isCompressionEnabled){
|
||||
request.setRawHeader("Accept-Encoding", "deflate, gzip");
|
||||
}
|
||||
|
||||
if (input->http_method == "GET") {
|
||||
reply = manager->get(request);
|
||||
} else if (input->http_method == "POST") {
|
||||
@ -332,15 +341,14 @@ void {{prefix}}HttpRequestWorker::execute({{prefix}}HttpRequestInput *input) {
|
||||
|
||||
void {{prefix}}HttpRequestWorker::on_manager_finished(QNetworkReply *reply) {
|
||||
error_type = reply->error();
|
||||
response = reply->readAll();
|
||||
error_str = reply->errorString();
|
||||
if (reply->rawHeaderPairs().count() > 0) {
|
||||
for (const auto &item : reply->rawHeaderPairs()) {
|
||||
headers.insert(item.first, item.second);
|
||||
}
|
||||
}
|
||||
process_response(reply);
|
||||
reply->deleteLater();
|
||||
process_form_response();
|
||||
emit on_execution_finished(this);
|
||||
}
|
||||
|
||||
@ -354,7 +362,7 @@ void {{prefix}}HttpRequestWorker::on_manager_timeout(QNetworkReply *reply) {
|
||||
emit on_execution_finished(this);
|
||||
}
|
||||
|
||||
void {{prefix}}HttpRequestWorker::process_form_response() {
|
||||
void {{prefix}}HttpRequestWorker::process_response(QNetworkReply *reply) {
|
||||
if (getResponseHeaders().contains(QString("Content-Disposition"))) {
|
||||
auto contentDisposition = getResponseHeaders().value(QString("Content-Disposition").toUtf8()).split(QString(";"), QString::SkipEmptyParts);
|
||||
auto contentType =
|
||||
@ -368,18 +376,61 @@ void {{prefix}}HttpRequestWorker::process_form_response() {
|
||||
}
|
||||
}
|
||||
{{prefix}}HttpFileElement felement;
|
||||
felement.saveToFile(QString(), workingDirectory + QDir::separator() + filename, filename, contentType, response.data());
|
||||
felement.saveToFile(QString(), workingDirectory + QDir::separator() + filename, filename, contentType, reply->readAll());
|
||||
files.insert(filename, felement);
|
||||
}
|
||||
|
||||
} else if (getResponseHeaders().contains(QString("Content-Type"))) {
|
||||
auto contentType = getResponseHeaders().value(QString("Content-Type").toUtf8()).split(QString(";"), QString::SkipEmptyParts);
|
||||
if ((contentType.count() > 0) && (contentType.first() == QString("multipart/form-data"))) {
|
||||
// TODO : Handle Multipart responses
|
||||
} else {
|
||||
if(headers.contains("Content-Encoding")){
|
||||
auto encoding = headers.value("Content-Encoding").split(QString(";"), QString::SkipEmptyParts);
|
||||
if(encoding.count() > 0){
|
||||
auto compressionTypes = encoding.first().split(',', QString::SkipEmptyParts);
|
||||
if(compressionTypes.contains("gzip", Qt::CaseInsensitive) || compressionTypes.contains("deflate", Qt::CaseInsensitive)){
|
||||
response = decompress(reply->readAll());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
response = reply->readAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray {{prefix}}HttpRequestWorker::decompress(const QByteArray& data){
|
||||
QByteArray result;
|
||||
bool sts = false;{{#contentCompression}}
|
||||
do{
|
||||
z_stream strm{};
|
||||
static const int CHUNK_SIZE = 2048;
|
||||
char out[CHUNK_SIZE];
|
||||
if (data.size() <= 4) {
|
||||
break;
|
||||
}
|
||||
strm.avail_in = data.size();
|
||||
strm.next_in = (Bytef*)(data.data());
|
||||
if(Z_OK != inflateInit2(&strm, 15 + 32)){
|
||||
break;
|
||||
}
|
||||
do {
|
||||
sts = false;
|
||||
strm.avail_out = CHUNK_SIZE;
|
||||
strm.next_out = (Bytef*)(out);
|
||||
if(inflate(&strm, Z_NO_FLUSH) < Z_OK){
|
||||
break;
|
||||
}
|
||||
result.append(out, CHUNK_SIZE - strm.avail_out);
|
||||
sts = true;
|
||||
} while (strm.avail_out == 0);
|
||||
inflateEnd(&strm);
|
||||
} while(false);{{/contentCompression}}
|
||||
return sts ? result : QByteArray();
|
||||
}
|
||||
|
||||
QSslConfiguration *{{prefix}}HttpRequestWorker::sslDefaultConfiguration;
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
|
@ -63,6 +63,7 @@ public:
|
||||
void setWorkingDirectory(const QString &path);
|
||||
{{prefix}}HttpFileElement getHttpFileElement(const QString &fieldname = QString());
|
||||
QByteArray *getMultiPartField(const QString &fieldname = QString());
|
||||
void setCompressionEnabled(bool enable);
|
||||
signals:
|
||||
void on_execution_finished({{prefix}}HttpRequestWorker *worker);
|
||||
|
||||
@ -73,8 +74,10 @@ private:
|
||||
QMap<QString, QByteArray *> multiPartFields;
|
||||
QString workingDirectory;
|
||||
int _timeOut;
|
||||
bool isCompressionEnabled;
|
||||
void on_manager_timeout(QNetworkReply *reply);
|
||||
void process_form_response();
|
||||
void process_response(QNetworkReply *reply);
|
||||
QByteArray decompress(const QByteArray& data);
|
||||
private slots:
|
||||
void on_manager_finished(QNetworkReply *reply);
|
||||
};
|
||||
|
@ -14,7 +14,8 @@ namespace {{this}} {
|
||||
_host(host),
|
||||
_port(port),
|
||||
_basePath(basePath),
|
||||
_timeOut(timeOut) {}
|
||||
_timeOut(timeOut),
|
||||
_compress(false) {}
|
||||
|
||||
{{classname}}::~{{classname}}() {
|
||||
}
|
||||
@ -47,6 +48,10 @@ void {{classname}}::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
void {{classname}}::enableContentCompression() {
|
||||
_compress = true;
|
||||
}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
@ -109,6 +114,7 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
|
||||
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
{{prefix}}HttpRequestInput input(fullPath, "{{httpMethod}}");
|
||||
{{#formParams}}{{^isFile}}
|
||||
input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}));{{/isFile}}{{#isFile}}
|
||||
@ -144,6 +150,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
{{#returnType}}
|
||||
{{#isListContainer}}
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
void setTimeOut(const int timeOut);
|
||||
void setWorkingDirectory(const QString &path);
|
||||
void addHeaders(const QString &key, const QString &value);
|
||||
void enableContentCompression();
|
||||
{{#operations}}{{#operation}}
|
||||
void {{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/operation}}{{/operations}}
|
||||
|
||||
@ -37,6 +38,7 @@ private:
|
||||
int _timeOut;
|
||||
QString _workingDirectory;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
bool _compress;
|
||||
{{#operations}}{{#operation}}
|
||||
void {{nickname}}Callback({{prefix}}HttpRequestWorker *worker);{{/operation}}{{/operations}}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
4.2.2-SNAPSHOT
|
||||
4.2.3-SNAPSHOT
|
@ -103,6 +103,10 @@ void PFXHttpRequestWorker::setWorkingDirectory(const QString &path) {
|
||||
}
|
||||
}
|
||||
|
||||
void PFXHttpRequestWorker::setCompressionEnabled(bool enable) {
|
||||
isCompressionEnabled = enable;
|
||||
}
|
||||
|
||||
QString PFXHttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
|
||||
// result structure follows RFC 5987
|
||||
bool need_utf_encoding = false;
|
||||
@ -311,6 +315,10 @@ void PFXHttpRequestWorker::execute(PFXHttpRequestInput *input) {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary);
|
||||
}
|
||||
|
||||
if(isCompressionEnabled){
|
||||
request.setRawHeader("Accept-Encoding", "deflate, gzip");
|
||||
}
|
||||
|
||||
if (input->http_method == "GET") {
|
||||
reply = manager->get(request);
|
||||
} else if (input->http_method == "POST") {
|
||||
@ -340,15 +348,14 @@ void PFXHttpRequestWorker::execute(PFXHttpRequestInput *input) {
|
||||
|
||||
void PFXHttpRequestWorker::on_manager_finished(QNetworkReply *reply) {
|
||||
error_type = reply->error();
|
||||
response = reply->readAll();
|
||||
error_str = reply->errorString();
|
||||
if (reply->rawHeaderPairs().count() > 0) {
|
||||
for (const auto &item : reply->rawHeaderPairs()) {
|
||||
headers.insert(item.first, item.second);
|
||||
}
|
||||
}
|
||||
process_response(reply);
|
||||
reply->deleteLater();
|
||||
process_form_response();
|
||||
emit on_execution_finished(this);
|
||||
}
|
||||
|
||||
@ -362,7 +369,7 @@ void PFXHttpRequestWorker::on_manager_timeout(QNetworkReply *reply) {
|
||||
emit on_execution_finished(this);
|
||||
}
|
||||
|
||||
void PFXHttpRequestWorker::process_form_response() {
|
||||
void PFXHttpRequestWorker::process_response(QNetworkReply *reply) {
|
||||
if (getResponseHeaders().contains(QString("Content-Disposition"))) {
|
||||
auto contentDisposition = getResponseHeaders().value(QString("Content-Disposition").toUtf8()).split(QString(";"), QString::SkipEmptyParts);
|
||||
auto contentType =
|
||||
@ -376,18 +383,37 @@ void PFXHttpRequestWorker::process_form_response() {
|
||||
}
|
||||
}
|
||||
PFXHttpFileElement felement;
|
||||
felement.saveToFile(QString(), workingDirectory + QDir::separator() + filename, filename, contentType, response.data());
|
||||
felement.saveToFile(QString(), workingDirectory + QDir::separator() + filename, filename, contentType, reply->readAll());
|
||||
files.insert(filename, felement);
|
||||
}
|
||||
|
||||
} else if (getResponseHeaders().contains(QString("Content-Type"))) {
|
||||
auto contentType = getResponseHeaders().value(QString("Content-Type").toUtf8()).split(QString(";"), QString::SkipEmptyParts);
|
||||
if ((contentType.count() > 0) && (contentType.first() == QString("multipart/form-data"))) {
|
||||
// TODO : Handle Multipart responses
|
||||
} else {
|
||||
if(headers.contains("Content-Encoding")){
|
||||
auto encoding = headers.value("Content-Encoding").split(QString(";"), QString::SkipEmptyParts);
|
||||
if(encoding.count() > 0){
|
||||
auto compressionTypes = encoding.first().split(',', QString::SkipEmptyParts);
|
||||
if(compressionTypes.contains("gzip", Qt::CaseInsensitive) || compressionTypes.contains("deflate", Qt::CaseInsensitive)){
|
||||
response = decompress(reply->readAll());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
response = reply->readAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray PFXHttpRequestWorker::decompress(const QByteArray& data){
|
||||
QByteArray result;
|
||||
bool sts = false;
|
||||
return sts ? result : QByteArray();
|
||||
}
|
||||
|
||||
QSslConfiguration *PFXHttpRequestWorker::sslDefaultConfiguration;
|
||||
|
||||
} // namespace test_namespace
|
||||
|
@ -71,6 +71,7 @@ public:
|
||||
void setWorkingDirectory(const QString &path);
|
||||
PFXHttpFileElement getHttpFileElement(const QString &fieldname = QString());
|
||||
QByteArray *getMultiPartField(const QString &fieldname = QString());
|
||||
void setCompressionEnabled(bool enable);
|
||||
signals:
|
||||
void on_execution_finished(PFXHttpRequestWorker *worker);
|
||||
|
||||
@ -81,8 +82,10 @@ private:
|
||||
QMap<QString, QByteArray *> multiPartFields;
|
||||
QString workingDirectory;
|
||||
int _timeOut;
|
||||
bool isCompressionEnabled;
|
||||
void on_manager_timeout(QNetworkReply *reply);
|
||||
void process_form_response();
|
||||
void process_response(QNetworkReply *reply);
|
||||
QByteArray decompress(const QByteArray& data);
|
||||
private slots:
|
||||
void on_manager_finished(QNetworkReply *reply);
|
||||
};
|
||||
|
@ -22,7 +22,8 @@ PFXPetApi::PFXPetApi(const QString &scheme, const QString &host, int port, const
|
||||
_host(host),
|
||||
_port(port),
|
||||
_basePath(basePath),
|
||||
_timeOut(timeOut) {}
|
||||
_timeOut(timeOut),
|
||||
_compress(false) {}
|
||||
|
||||
PFXPetApi::~PFXPetApi() {
|
||||
}
|
||||
@ -55,6 +56,10 @@ void PFXPetApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
void PFXPetApi::enableContentCompression() {
|
||||
_compress = true;
|
||||
}
|
||||
|
||||
void PFXPetApi::addPet(const PFXPet &body) {
|
||||
QString fullPath = QString("%1://%2%3%4%5")
|
||||
.arg(_scheme)
|
||||
@ -66,6 +71,7 @@ void PFXPetApi::addPet(const PFXPet &body) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
QString output = body.asJson();
|
||||
@ -87,6 +93,7 @@ void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -113,6 +120,7 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QString &api_key) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "DELETE");
|
||||
|
||||
if (api_key != nullptr) {
|
||||
@ -135,6 +143,7 @@ void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -196,6 +205,7 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -214,6 +224,7 @@ void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
QList<PFXPet> output;
|
||||
QString json(worker->response);
|
||||
@ -285,6 +296,7 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -303,6 +315,7 @@ void PFXPetApi::findPetsByTagsCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
QList<PFXPet> output;
|
||||
QString json(worker->response);
|
||||
@ -339,6 +352,7 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -357,6 +371,7 @@ void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
PFXPet output(QString(worker->response));
|
||||
worker->deleteLater();
|
||||
@ -381,6 +396,7 @@ void PFXPetApi::updatePet(const PFXPet &body) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "PUT");
|
||||
|
||||
QString output = body.asJson();
|
||||
@ -402,6 +418,7 @@ void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -428,6 +445,7 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QString &name, con
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
input.add_var("name", ::test_namespace::toStringValue(name));
|
||||
@ -448,6 +466,7 @@ void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -474,6 +493,7 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QString &additional_metad
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata));
|
||||
@ -494,6 +514,7 @@ void PFXPetApi::uploadFileCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
PFXApiResponse output(QString(worker->response));
|
||||
worker->deleteLater();
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
void setTimeOut(const int timeOut);
|
||||
void setWorkingDirectory(const QString &path);
|
||||
void addHeaders(const QString &key, const QString &value);
|
||||
void enableContentCompression();
|
||||
|
||||
void addPet(const PFXPet &body);
|
||||
void deletePet(const qint64 &pet_id, const QString &api_key);
|
||||
@ -54,6 +55,7 @@ private:
|
||||
int _timeOut;
|
||||
QString _workingDirectory;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
bool _compress;
|
||||
|
||||
void addPetCallback(PFXHttpRequestWorker *worker);
|
||||
void deletePetCallback(PFXHttpRequestWorker *worker);
|
||||
|
@ -22,7 +22,8 @@ PFXStoreApi::PFXStoreApi(const QString &scheme, const QString &host, int port, c
|
||||
_host(host),
|
||||
_port(port),
|
||||
_basePath(basePath),
|
||||
_timeOut(timeOut) {}
|
||||
_timeOut(timeOut),
|
||||
_compress(false) {}
|
||||
|
||||
PFXStoreApi::~PFXStoreApi() {
|
||||
}
|
||||
@ -55,6 +56,10 @@ void PFXStoreApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
void PFXStoreApi::enableContentCompression() {
|
||||
_compress = true;
|
||||
}
|
||||
|
||||
void PFXStoreApi::deleteOrder(const QString &order_id) {
|
||||
QString fullPath = QString("%1://%2%3%4%5")
|
||||
.arg(_scheme)
|
||||
@ -69,6 +74,7 @@ void PFXStoreApi::deleteOrder(const QString &order_id) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "DELETE");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -87,6 +93,7 @@ void PFXStoreApi::deleteOrderCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -110,6 +117,7 @@ void PFXStoreApi::getInventory() {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -128,6 +136,7 @@ void PFXStoreApi::getInventoryCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
QMap<QString, qint32> output;
|
||||
QString json(worker->response);
|
||||
@ -164,6 +173,7 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -182,6 +192,7 @@ void PFXStoreApi::getOrderByIdCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
PFXOrder output(QString(worker->response));
|
||||
worker->deleteLater();
|
||||
@ -206,6 +217,7 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
QString output = body.asJson();
|
||||
@ -227,6 +239,7 @@ void PFXStoreApi::placeOrderCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
PFXOrder output(QString(worker->response));
|
||||
worker->deleteLater();
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
void setTimeOut(const int timeOut);
|
||||
void setWorkingDirectory(const QString &path);
|
||||
void addHeaders(const QString &key, const QString &value);
|
||||
void enableContentCompression();
|
||||
|
||||
void deleteOrder(const QString &order_id);
|
||||
void getInventory();
|
||||
@ -49,6 +50,7 @@ private:
|
||||
int _timeOut;
|
||||
QString _workingDirectory;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
bool _compress;
|
||||
|
||||
void deleteOrderCallback(PFXHttpRequestWorker *worker);
|
||||
void getInventoryCallback(PFXHttpRequestWorker *worker);
|
||||
|
@ -22,7 +22,8 @@ PFXUserApi::PFXUserApi(const QString &scheme, const QString &host, int port, con
|
||||
_host(host),
|
||||
_port(port),
|
||||
_basePath(basePath),
|
||||
_timeOut(timeOut) {}
|
||||
_timeOut(timeOut),
|
||||
_compress(false) {}
|
||||
|
||||
PFXUserApi::~PFXUserApi() {
|
||||
}
|
||||
@ -55,6 +56,10 @@ void PFXUserApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
void PFXUserApi::enableContentCompression() {
|
||||
_compress = true;
|
||||
}
|
||||
|
||||
void PFXUserApi::createUser(const PFXUser &body) {
|
||||
QString fullPath = QString("%1://%2%3%4%5")
|
||||
.arg(_scheme)
|
||||
@ -66,6 +71,7 @@ void PFXUserApi::createUser(const PFXUser &body) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
QString output = body.asJson();
|
||||
@ -87,6 +93,7 @@ void PFXUserApi::createUserCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -110,6 +117,7 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
|
||||
@ -132,6 +140,7 @@ void PFXUserApi::createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker)
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -155,6 +164,7 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
|
||||
@ -177,6 +187,7 @@ void PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker *worker)
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -203,6 +214,7 @@ void PFXUserApi::deleteUser(const QString &username) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "DELETE");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -221,6 +233,7 @@ void PFXUserApi::deleteUserCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -247,6 +260,7 @@ void PFXUserApi::getUserByName(const QString &username) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -265,6 +279,7 @@ void PFXUserApi::getUserByNameCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
PFXUser output(QString(worker->response));
|
||||
worker->deleteLater();
|
||||
@ -301,6 +316,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -319,6 +335,7 @@ void PFXUserApi::loginUserCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
QString output;
|
||||
::test_namespace::fromStringValue(QString(worker->response), output);
|
||||
@ -344,6 +361,7 @@ void PFXUserApi::logoutUser() {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "GET");
|
||||
|
||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
||||
@ -362,6 +380,7 @@ void PFXUserApi::logoutUserCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
@ -388,6 +407,7 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
|
||||
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
||||
worker->setTimeOut(_timeOut);
|
||||
worker->setWorkingDirectory(_workingDirectory);
|
||||
worker->setCompressionEnabled(_compress);
|
||||
PFXHttpRequestInput input(fullPath, "PUT");
|
||||
|
||||
QString output = body.asJson();
|
||||
@ -409,6 +429,7 @@ void PFXUserApi::updateUserCallback(PFXHttpRequestWorker *worker) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
} else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
||||
}
|
||||
worker->deleteLater();
|
||||
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
void setTimeOut(const int timeOut);
|
||||
void setWorkingDirectory(const QString &path);
|
||||
void addHeaders(const QString &key, const QString &value);
|
||||
void enableContentCompression();
|
||||
|
||||
void createUser(const PFXUser &body);
|
||||
void createUsersWithArrayInput(const QList<PFXUser> &body);
|
||||
@ -53,6 +54,7 @@ private:
|
||||
int _timeOut;
|
||||
QString _workingDirectory;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
bool _compress;
|
||||
|
||||
void createUserCallback(PFXHttpRequestWorker *worker);
|
||||
void createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker);
|
||||
|
Loading…
x
Reference in New Issue
Block a user