FluNetwork add openLog funcation

This commit is contained in:
朱子楚\zhuzi 2023-12-07 23:01:09 +08:00
parent 13223a11a2
commit 7086df10f0
6 changed files with 49 additions and 4 deletions

View File

@ -25,7 +25,7 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
FluNetwork.openLog = true FluNetwork.openLog = false
FluNetwork.setInterceptor(function(param){ FluNetwork.setInterceptor(function(param){
param.addHeader("Token","000000000000000000000") param.addHeader("Token","000000000000000000000")
}) })

View File

@ -280,6 +280,21 @@ FluContentPage{
.go(callable) .go(callable)
} }
} }
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Open Log"
onClicked: {
text_info.text = ""
FluNetwork.postJson("https://httpbingo.org/post")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
.openLog(true)
.bind(root)
.go(callable)
}
}
FluButton{ FluButton{
implicitWidth: parent.width implicitWidth: parent.width
implicitHeight: 36 implicitHeight: 36

View File

@ -25,7 +25,7 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
FluNetwork.openLog = true FluNetwork.openLog = false
FluNetwork.setInterceptor(function(param){ FluNetwork.setInterceptor(function(param){
param.addHeader("Token","000000000000000000000") param.addHeader("Token","000000000000000000000")
}) })

View File

@ -281,6 +281,21 @@ FluContentPage{
.go(callable) .go(callable)
} }
} }
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "Open Log"
onClicked: {
text_info.text = ""
FluNetwork.postJson("https://httpbingo.org/post")
.add("name","孙悟空")
.add("age",500)
.add("address","花果山水帘洞")
.openLog(true)
.bind(root)
.go(callable)
}
}
FluButton{ FluButton{
implicitWidth: parent.width implicitWidth: parent.width
implicitHeight: 36 implicitHeight: 36

View File

@ -54,6 +54,13 @@ int NetworkParams::getRetry(){
return FluNetwork::getInstance()->retry(); return FluNetwork::getInstance()->retry();
} }
bool NetworkParams::getOpenLog(){
if(!_openLog.isNull()){
return _openLog.toBool();
}
return FluNetwork::getInstance()->openLog();
}
DownloadParam::DownloadParam(QObject *parent) DownloadParam::DownloadParam(QObject *parent)
: QObject{parent} : QObject{parent}
{ {
@ -129,6 +136,11 @@ NetworkParams* NetworkParams::bind(QObject* target){
return this; return this;
} }
NetworkParams* NetworkParams::openLog(QVariant val){
_openLog = val;
return this;
}
QString NetworkParams::buildCacheKey(){ QString NetworkParams::buildCacheKey(){
QJsonObject obj; QJsonObject obj;
obj.insert("url",_url); obj.insert("url",_url);
@ -488,7 +500,7 @@ void FluNetwork::sendRequest(QNetworkAccessManager* manager,QNetworkRequest requ
} }
void FluNetwork::printRequestStartLog(QNetworkRequest request,NetworkParams* params){ void FluNetwork::printRequestStartLog(QNetworkRequest request,NetworkParams* params){
if(!_openLog){ if(!params->getOpenLog()){
return; return;
} }
qDebug()<<"<------"<<qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString())<<"Request Start ------>"; qDebug()<<"<------"<<qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString())<<"Request Start ------>";
@ -516,7 +528,7 @@ void FluNetwork::printRequestStartLog(QNetworkRequest request,NetworkParams* par
} }
void FluNetwork::printRequestEndLog(QNetworkRequest request,NetworkParams* params,QNetworkReply*& reply,const QString& response){ void FluNetwork::printRequestEndLog(QNetworkRequest request,NetworkParams* params,QNetworkReply*& reply,const QString& response){
if(!_openLog){ if(!params->getOpenLog()){
return; return;
} }
qDebug()<<"<------"<<qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString())<<"Request End ------>"; qDebug()<<"<------"<<qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString())<<"Request End ------>";

View File

@ -67,11 +67,13 @@ public:
Q_INVOKABLE NetworkParams* setCacheMode(int val); Q_INVOKABLE NetworkParams* setCacheMode(int val);
Q_INVOKABLE NetworkParams* toDownload(QString destPath,bool append = false); Q_INVOKABLE NetworkParams* toDownload(QString destPath,bool append = false);
Q_INVOKABLE NetworkParams* bind(QObject* target); Q_INVOKABLE NetworkParams* bind(QObject* target);
Q_INVOKABLE NetworkParams* openLog(QVariant val);
Q_INVOKABLE void go(NetworkCallable* result); Q_INVOKABLE void go(NetworkCallable* result);
QString buildCacheKey(); QString buildCacheKey();
QString method2String(); QString method2String();
int getTimeout(); int getTimeout();
int getRetry(); int getRetry();
bool getOpenLog();
public: public:
DownloadParam* _downloadParam = nullptr; DownloadParam* _downloadParam = nullptr;
QObject* _target = nullptr; QObject* _target = nullptr;
@ -85,6 +87,7 @@ public:
QMap<QString, QVariant> _fileMap; QMap<QString, QVariant> _fileMap;
int _timeout = -1; int _timeout = -1;
int _retry = -1; int _retry = -1;
QVariant _openLog;
int _cacheMode = FluNetworkType::CacheMode::NoCache; int _cacheMode = FluNetworkType::CacheMode::NoCache;
}; };