-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestscreencontroller.cpp
58 lines (46 loc) · 1.94 KB
/
requestscreencontroller.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "requestscreencontroller.h"
#include "Constants.h"
RequestScreenController::RequestScreenController(QObject *parent) :
QObject(parent)
{
}
void RequestScreenController::setResponseCallback(const std::function<void(HttpResponse)> callback) {
this->callback = callback;
}
RequestScreenController::~RequestScreenController() {
delete req;
qDebug() <<" REQUEST SCREEN CONTROLLER DELETED";
}
void RequestScreenController::cancelRequest() {
req->cancelRequest();
}
void RequestScreenController::start() {
connect(req,&HttpRequest::requestFinished,this,[&](bool error,int responseCode,
const QString& errorString,
const QByteArray& response, const QList<QPair<QByteArray,QByteArray>>& responseHeaders, const QList<QNetworkCookie>& cookies)->void{
HttpResponse httpResponse{error,responseCode,errorString,response,responseHeaders,cookies};
callback(httpResponse);
});
req->start();
}
void RequestScreenController::newRequest(QUrl *url, QString *requestMethod,
QMap<QString, QString> *headers, QByteArray *body){
newRequest(url,requestMethod,headers,body,nullptr);
}
void RequestScreenController::newRequest(QUrl *url, QString *requestMethod,
QMap<QString, QString> *headers, QUrlQuery *urlQuery) {
newRequest(url,requestMethod,headers,nullptr,urlQuery);
}
void RequestScreenController::newRequest( QUrl *url,
QString *requestMethod,
QMap<QString, QString> *headers,
QByteArray *body, QUrlQuery *urlQuery) {
if(req) {
delete req;
}
req = new HttpRequest(this);
req->newRequest(url,requestMethod,headers,body,urlQuery);
}
void RequestScreenController::newRequest(QUrl* url) {
newRequest(url,new QString{Constants::HttpMethods::GET},nullptr,nullptr,nullptr);
}