opt: change ArticleNetworkAccessManager's method createRequest to getArticleReply

createRequest was the parent's protected method ,give the impression that the derived class has override it.

rename it to clacify the misunderstand.
This commit is contained in:
Xiao YiFang 2022-05-19 07:14:36 +08:00
parent bde86d7b88
commit d73956b90d
3 changed files with 14 additions and 22 deletions

View file

@ -150,12 +150,11 @@ using std::string;
return size;
}
QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
QNetworkRequest const & req,
QIODevice * outgoingData )
QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest const & req )
{
QUrl url;
if ( op == GetOperation )
auto op = GetOperation;
// if ( op == GetOperation )
{
if ( req.url().scheme() == "qrcx" )
{
@ -169,7 +168,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
QNetworkRequest newReq( req );
newReq.setUrl( newUrl );
return QNetworkAccessManager::createRequest( op, newReq, outgoingData );
return QNetworkAccessManager::createRequest( op, newReq, nullptr );
}
url=req.url();
@ -237,7 +236,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
QNetworkRequest newReq( req );
newReq.setUrl( newUrl );
return QNetworkAccessManager::createRequest( op, newReq, outgoingData );
return QNetworkAccessManager::createRequest( op, newReq, nullptr );
}
}
@ -250,7 +249,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
newReq.setRawHeader("User-Agent", req.rawHeader("User-Agent").replace(qApp->applicationName().toUtf8(), ""));
}
QNetworkReply * reply = QNetworkAccessManager::createRequest( op, newReq, outgoingData );
QNetworkReply * reply = QNetworkAccessManager::createRequest( op, newReq, nullptr );
if( url.scheme() == "https")
{
@ -260,8 +259,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
#endif
}
return op == QNetworkAccessManager::GetOperation
|| op == QNetworkAccessManager::HeadOperation ? new AllowFrameReply( reply ) : reply;
return new AllowFrameReply( reply );
}
sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
@ -528,7 +526,7 @@ void LocalSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
QNetworkRequest request;
request.setUrl( url );
QNetworkReply * reply = this->mManager.createRequest( QNetworkAccessManager::GetOperation, request );
QNetworkReply * reply = this->mManager.getArticleReply( request );
connect( reply, &QNetworkReply::finished, requestJob, [ = ]() { requestJob->reply( "text/html", reply ); } );
connect( requestJob, &QObject::destroyed, reply, &QObject::deleteLater );
}

View file

@ -122,11 +122,7 @@ public:
sptr< Dictionary::DataRequest > getResource( QUrl const & url,
QString & contentType );
// protected:
virtual QNetworkReply * createRequest( Operation op,
QNetworkRequest const & req,
QIODevice * outgoingData = nullptr);
virtual QNetworkReply * getArticleReply( QNetworkRequest const & req );
};
@ -202,18 +198,16 @@ private slots:
void finishedSlot();
};
class LocalSchemeHandler : public QWebEngineUrlSchemeHandler
{
Q_OBJECT
Q_OBJECT
public:
LocalSchemeHandler(ArticleNetworkAccessManager &articleNetMgr);
void requestStarted(QWebEngineUrlRequestJob *requestJob);
LocalSchemeHandler( ArticleNetworkAccessManager & articleNetMgr );
void requestStarted( QWebEngineUrlRequestJob * requestJob );
protected:
private:
ArticleNetworkAccessManager& mManager;
ArticleNetworkAccessManager & mManager;
QNetworkAccessManager mgr;
};
#endif

View file

@ -10,7 +10,7 @@ void ResourceSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
QNetworkRequest request;
request.setUrl(url);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
QNetworkReply *reply = this->mManager.createRequest(QNetworkAccessManager::GetOperation, request);
QNetworkReply *reply = this->mManager.getArticleReply( request);
connect(reply, &QNetworkReply::finished, requestJob, [=]() {
if (reply->error() == QNetworkReply::ContentNotFoundError) {
requestJob->fail(QWebEngineUrlRequestJob::UrlNotFound);