mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-16 22:00:51 +00:00
* Add initial version of File upload and download for Qt5 client * Update after reviews * Remove unused header
95 lines
2.6 KiB
C++
95 lines
2.6 KiB
C++
/**
|
|
* OpenAPI Petstore
|
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
*
|
|
* The version of the OpenAPI document: 1.0.0
|
|
*
|
|
*
|
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
* https://openapi-generator.tech
|
|
* Do not edit the class manually.
|
|
*/
|
|
|
|
/**
|
|
* Based on http://www.creativepulse.gr/en/blog/2014/restful-api-requests-using-qt-cpp-for-linux-mac-osx-ms-windows
|
|
* By Alex Stylianos
|
|
*
|
|
**/
|
|
|
|
#ifndef OAI_HTTPREQUESTWORKER_H
|
|
#define OAI_HTTPREQUESTWORKER_H
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QTimer>
|
|
#include <QMap>
|
|
#include <QNetworkAccessManager>
|
|
#include <QNetworkReply>
|
|
|
|
|
|
#include "OAIHttpFileElement.h"
|
|
|
|
namespace OpenAPI {
|
|
|
|
enum OAIHttpRequestVarLayout {NOT_SET, ADDRESS, URL_ENCODED, MULTIPART};
|
|
|
|
|
|
class OAIHttpRequestInput {
|
|
|
|
public:
|
|
QString url_str;
|
|
QString http_method;
|
|
OAIHttpRequestVarLayout var_layout;
|
|
QMap<QString, QString> vars;
|
|
QMap<QString, QString> headers;
|
|
QList<OAIHttpFileElement> files;
|
|
QByteArray request_body;
|
|
|
|
OAIHttpRequestInput();
|
|
OAIHttpRequestInput(QString v_url_str, QString v_http_method);
|
|
void initialize();
|
|
void add_var(QString key, QString value);
|
|
void add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type);
|
|
|
|
};
|
|
|
|
|
|
class OAIHttpRequestWorker : public QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
QByteArray response;
|
|
QNetworkReply::NetworkError error_type;
|
|
QString error_str;
|
|
QTimer *timer;
|
|
explicit OAIHttpRequestWorker(QObject *parent = nullptr);
|
|
virtual ~OAIHttpRequestWorker();
|
|
|
|
QMap<QString, QString> getResponseHeaders() const;
|
|
QString http_attribute_encode(QString attribute_name, QString input);
|
|
void execute(OAIHttpRequestInput *input);
|
|
static QSslConfiguration* sslDefaultConfiguration;
|
|
void setTimeOut(int tout);
|
|
void setWorkingDirectory(const QString &path);
|
|
OAIHttpFileElement getHttpFileElement(const QString &fieldname = QString());
|
|
QByteArray* getMultiPartField(const QString &fieldname = QString());
|
|
signals:
|
|
void on_execution_finished(OAIHttpRequestWorker *worker);
|
|
|
|
private:
|
|
QNetworkAccessManager *manager;
|
|
QMap<QString, QString> headers;
|
|
QMap<QString, OAIHttpFileElement> files;
|
|
QMap<QString, QByteArray*> multiPartFields;
|
|
QString workingDirectory;
|
|
int timeout;
|
|
void on_manager_timeout(QNetworkReply *reply);
|
|
void process_form_response();
|
|
private slots:
|
|
void on_manager_finished(QNetworkReply *reply);
|
|
};
|
|
|
|
}
|
|
|
|
#endif // OAI_HTTPREQUESTWORKER_H
|