From 15207cf40063ffcb5fc6c59b2fbbc2582fc0e340 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Sat, 26 Oct 2024 19:35:27 +0800 Subject: [PATCH] opt: reply remove unnecessary signal (#1866) * opt: remove unnecessary signal --------- Co-authored-by: shenleban tongying --- src/article_netmgr.cc | 47 +++++-------------------------------------- src/article_netmgr.hh | 11 ++-------- 2 files changed, 7 insertions(+), 51 deletions(-) diff --git a/src/article_netmgr.cc b/src/article_netmgr.cc index 53d08962..33e33963 100644 --- a/src/article_netmgr.cc +++ b/src/article_netmgr.cc @@ -22,9 +22,11 @@ AllowFrameReply::AllowFrameReply( QNetworkReply * _reply ): setRequest( baseReply->request() ); setUrl( baseReply->url() ); - // Signals to own slots - - connect( baseReply, &QNetworkReply::metaDataChanged, this, &AllowFrameReply::applyMetaData ); + QList< QByteArray > rawHeaders = baseReply->rawHeaderList(); + for ( const auto & header : rawHeaders ) { + if ( header.toLower() != "x-frame-options" ) + setRawHeader( header, baseReply->rawHeader( header ) ); + } connect( baseReply, &QNetworkReply::errorOccurred, this, &AllowFrameReply::applyError ); @@ -32,45 +34,11 @@ AllowFrameReply::AllowFrameReply( QNetworkReply * _reply ): // Redirect QNetworkReply signals - connect( baseReply, &QNetworkReply::downloadProgress, this, &QNetworkReply::downloadProgress ); - - connect( baseReply, &QNetworkReply::encrypted, this, &QNetworkReply::encrypted ); - connect( baseReply, &QNetworkReply::finished, this, &QNetworkReply::finished ); - connect( baseReply, - &QNetworkReply::preSharedKeyAuthenticationRequired, - this, - &QNetworkReply::preSharedKeyAuthenticationRequired ); - - connect( baseReply, &QNetworkReply::redirected, this, &QNetworkReply::redirected ); - - connect( baseReply, &QNetworkReply::sslErrors, this, &QNetworkReply::sslErrors ); - - connect( baseReply, &QNetworkReply::uploadProgress, this, &QNetworkReply::uploadProgress ); - - // Redirect QIODevice signals - - connect( baseReply, &QIODevice::aboutToClose, this, &QIODevice::aboutToClose ); - - connect( baseReply, &QIODevice::bytesWritten, this, &QIODevice::bytesWritten ); - - connect( baseReply, &QIODevice::readChannelFinished, this, &QIODevice::readChannelFinished ); - setOpenMode( QIODevice::ReadOnly ); } -void AllowFrameReply::applyMetaData() -{ - // The webengine does not support to customize the headers right now ,maybe until Qt6.7 there should be some api supports -} - -void AllowFrameReply::setReadBufferSize( qint64 size ) -{ - QNetworkReply::setReadBufferSize( size ); - baseReply->setReadBufferSize( size ); -} - qint64 AllowFrameReply::bytesAvailable() const { return baseReply->bytesAvailable(); @@ -89,11 +57,6 @@ qint64 AllowFrameReply::readData( char * data, qint64 maxSize ) baseReply->read( data, size ); return size; } -void AllowFrameReply::finishedSlot() -{ - setFinished( true ); - emit finished(); -} QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest const & req ) { diff --git a/src/article_netmgr.hh b/src/article_netmgr.hh index 3b93a20b..60e98f25 100644 --- a/src/article_netmgr.hh +++ b/src/article_netmgr.hh @@ -42,8 +42,6 @@ public: delete baseReply; } - // QNetworkReply virtual functions - void setReadBufferSize( qint64 size ); void close() { baseReply->close(); @@ -51,7 +49,7 @@ public: // QIODevice virtual functions qint64 bytesAvailable() const; - bool atEnd() const + bool atEnd() const override { return baseReply->atEnd(); } @@ -81,11 +79,7 @@ public: } public slots: - - // Own AllowFrameReply slots - void applyMetaData(); void applyError( QNetworkReply::NetworkError code ); - // void readDataFromBase(); // Redirect QNetworkReply slots virtual void abort() @@ -96,7 +90,6 @@ public slots: { baseReply->ignoreSslErrors(); } - void finishedSlot(); protected: // QNetworkReply virtual functions @@ -186,7 +179,7 @@ public: protected: virtual qint64 bytesAvailable() const; - bool atEnd() const; + bool atEnd() const override; virtual void abort() {} virtual qint64 readData( char * data, qint64 maxSize );