diff --git a/doric-Qt/doric/plugin/DoricNetworkPlugin.cpp b/doric-Qt/doric/plugin/DoricNetworkPlugin.cpp index 1157db8d..9dc9d945 100644 --- a/doric-Qt/doric/plugin/DoricNetworkPlugin.cpp +++ b/doric-Qt/doric/plugin/DoricNetworkPlugin.cpp @@ -1,4 +1,5 @@ #include "DoricNetworkPlugin.h" +#include "engine/DoricPromise.h" #include "utils/DoricNetworkService.h" #include @@ -9,10 +10,20 @@ void DoricNetworkPlugin::request(QString jsValueString, QString callbackId) { QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8()); QJsonValue jsValue = document.object(); - DoricNetworkService::getInstance()->request(jsValue, qApp, - [](int code, QByteArray data) { - qDebug() << code; - qDebug() << data; - qDebug() << ""; - }); + DoricNetworkService::getInstance()->request( + jsValue, qApp, + [this, callbackId](int code, QList headers, QByteArray data) { + getContext()->getDriver()->asyncCall( + [this, callbackId, code, headers, data] { + QMap map; + map.insert("status", code); + map.insert("headers", QVariant::fromValue(headers)); + map.insert("data", QString(data)); + + QVariantList args; + args.append(map); + DoricPromise::resolve(getContext(), callbackId, args); + }, + DoricThreadMode::JS); + }); } diff --git a/doric-Qt/doric/utils/DoricNetworkService.h b/doric-Qt/doric/utils/DoricNetworkService.h index 7845b9cd..eab945b9 100644 --- a/doric-Qt/doric/utils/DoricNetworkService.h +++ b/doric-Qt/doric/utils/DoricNetworkService.h @@ -35,6 +35,10 @@ public: } } + if (timeoutVal.isDouble()) { + networkAccessManager.setTransferTimeout(timeoutVal.toInt()); + } + if (method == "get") { httpRequest.setUrl(QUrl(url)); QNetworkReply *reply = networkAccessManager.get(httpRequest); @@ -44,9 +48,9 @@ public: reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (reply->error() == QNetworkReply::NoError) { - emit response(statusCode, reply->readAll()); + emit response(statusCode, reply->rawHeaderList(), reply->readAll()); } else { - emit response(statusCode, QByteArray()); + emit response(statusCode, reply->rawHeaderList(), QByteArray()); } reply->deleteLater(); @@ -56,7 +60,7 @@ public: } signals: void run(QJsonValue jsValue); - void response(int code, QByteArray data); + void response(int code, QList headers, QByteArray data); }; class DoricNetworkService : public QObject {