Skip to content

Commit

Permalink
#1615 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Jan 29, 2025
1 parent f5038d5 commit c64b329
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/librssguard-gmail/src/gmailnetworkfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
class RootItem;
class GmailServiceRoot;
class OAuth2Service;
class Downloader;

class GmailNetworkFactory : public QObject {
Q_OBJECT
Expand Down
1 change: 0 additions & 1 deletion src/librssguard-reddit/src/redditnetworkfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
class RootItem;
class RedditServiceRoot;
class OAuth2Service;
class Downloader;

struct Subreddit {};

Expand Down
10 changes: 10 additions & 0 deletions src/librssguard-standard/src/gui/formstandardfeeddetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ void FormStandardFeedDetails::apply() {
std_feed->setDontUseRawXmlSaving(m_standardFeedExpDetails->m_ui.m_cbDontUseRawXml->isChecked());
}

if (isChangeAllowed(m_standardFeedExpDetails->m_ui.m_mcbEnableHttp2)) {
std_feed->setHttp2Status(static_cast<NetworkFactory::Http2Status>(m_standardFeedExpDetails->m_ui.m_cmbEnableHttp2
->currentData()
.toInt()));
}

std_feed->setCreationDate(QDateTime::currentDateTime());
std_feed->setLastEtag({});

Expand Down Expand Up @@ -192,6 +198,8 @@ void FormStandardFeedDetails::loadFeedData() {

m_standardFeedExpDetails->m_ui.m_mcbDontUseRawXml
->addActionWidget(m_standardFeedExpDetails->m_ui.m_cbDontUseRawXml);
m_standardFeedExpDetails->m_ui.m_mcbEnableHttp2->addActionWidget(m_standardFeedExpDetails->m_ui.m_lblEnableHttp2);
m_standardFeedExpDetails->m_ui.m_mcbEnableHttp2->addActionWidget(m_standardFeedExpDetails->m_ui.m_cmbEnableHttp2);
}
else {
// We hide batch selectors.
Expand Down Expand Up @@ -220,5 +228,7 @@ void FormStandardFeedDetails::loadFeedData() {
m_standardFeedDetails->setExistingFeed(std_feed);

m_standardFeedExpDetails->m_ui.m_cbDontUseRawXml->setChecked(std_feed->dontUseRawXmlSaving());
m_standardFeedExpDetails->m_ui.m_cmbEnableHttp2
->setCurrentIndex(m_standardFeedExpDetails->m_ui.m_cmbEnableHttp2->findData(int(std_feed->http2Status())));
}
}
5 changes: 5 additions & 0 deletions src/librssguard-standard/src/gui/standardfeedexpdetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ StandardFeedExpDetails::StandardFeedExpDetails(QWidget* parent) : QWidget(parent
"This setting is useful when raw XML parsing of the feed is very slow, this "
"happens for feed which do have very long contents."),
false);

m_ui.m_cmbEnableHttp2->addItem(tr("Use application settings"),
QVariant::fromValue(int(NetworkFactory::Http2Status::DontSet)));
m_ui.m_cmbEnableHttp2->addItem(tr("Enabled"), QVariant::fromValue(int(NetworkFactory::Http2Status::Enabled)));
m_ui.m_cmbEnableHttp2->addItem(tr("Disabled"), QVariant::fromValue(int(NetworkFactory::Http2Status::Disabled)));
}
61 changes: 51 additions & 10 deletions src/librssguard-standard/src/gui/standardfeedexpdetails.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,53 @@
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="MultiFeedEditCheckBox" name="m_mcbDontUseRawXml"/>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="m_cbDontUseRawXml">
<property name="text">
<string>Use older mechanism for extracting raw XML data</string>
</property>
</widget>
<item row="2" column="0" colspan="2">
<widget class="HelpSpoiler" name="m_helpDontUseRawXml" native="true"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="HelpSpoiler" name="m_helpDontUseRawXml" native="true"/>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="MultiFeedEditCheckBox" name="m_mcbDontUseRawXml"/>
</item>
<item>
<widget class="QCheckBox" name="m_cbDontUseRawXml">
<property name="text">
<string>Use older mechanism for extracting raw XML data</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="MultiFeedEditCheckBox" name="m_mcbEnableHttp2"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbEnableHttp2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="m_lblEnableHttp2">
<property name="text">
<string>Enable HTTP/2</string>
</property>
<property name="buddy">
<cstring>m_cmbEnableHttp2</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
Expand All @@ -42,6 +77,12 @@
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_mcbEnableHttp2</tabstop>
<tabstop>m_cmbEnableHttp2</tabstop>
<tabstop>m_mcbDontUseRawXml</tabstop>
<tabstop>m_cbDontUseRawXml</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
14 changes: 13 additions & 1 deletion src/librssguard-standard/src/standardfeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ StandardFeed::StandardFeed(RootItem* parent_item) : Feed(parent_item) {
m_password = QString();
m_httpHeaders = {};
m_dontUseRawXmlSaving = false;
m_http2Status = NetworkFactory::Http2Status::DontSet;
}

StandardFeed::StandardFeed(const StandardFeed& other) : Feed(other) {
Expand All @@ -66,6 +67,7 @@ StandardFeed::StandardFeed(const StandardFeed& other) : Feed(other) {
m_password = other.password();
m_dontUseRawXmlSaving = other.dontUseRawXmlSaving();
m_httpHeaders = other.httpHeaders();
m_http2Status = other.http2Status();
}

QList<QAction*> StandardFeed::contextMenuFeedsList() {
Expand All @@ -88,7 +90,7 @@ QString StandardFeed::additionalTooltip() const {
.toStdList();
QStringList fltrs = FROM_STD_LIST(QStringList, std_fltrs);

// TODO: toto je v podstatě zkopirovane z Feed...
// TODO: Basically copied from base implementation.
QString base_tooltip =
tr("Auto-update status: %1\n"
"Active message filters: %2\n"
Expand All @@ -113,6 +115,14 @@ QString StandardFeed::additionalTooltip() const {
!dontUseRawXmlSaving() ? tr("yes") : tr("no"));
}

NetworkFactory::Http2Status StandardFeed::http2Status() const {
return m_http2Status;
}

void StandardFeed::setHttp2Status(NetworkFactory::Http2Status status) {
m_http2Status = status;
}

bool StandardFeed::canBeDeleted() const {
return true;
}
Expand Down Expand Up @@ -167,6 +177,7 @@ QVariantHash StandardFeed::customDatabaseData() const {
data[QSL("password")] = TextFactory::encrypt(password());
data[QSL("dont_use_raw_xml_saving")] = dontUseRawXmlSaving();
data[QSL("http_headers")] = httpHeaders();
data[QSL("http2_status")] = int(http2Status());

return data;
}
Expand All @@ -181,6 +192,7 @@ void StandardFeed::setCustomDatabaseData(const QVariantHash& data) {
setPassword(TextFactory::decrypt(data[QSL("password")].toString()));
setDontUseRawXmlSaving(data[QSL("dont_use_raw_xml_saving")].toBool());
setHttpHeaders(data[QSL("http_headers")].toHash());
setHttp2Status(NetworkFactory::Http2Status(data[QSL("http2_status")].toInt()));
}

QString StandardFeed::typeToString(StandardFeed::Type type) {
Expand Down
4 changes: 4 additions & 0 deletions src/librssguard-standard/src/standardfeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class StandardFeed : public Feed {
QString password() const;
void setPassword(const QString& password);

NetworkFactory::Http2Status http2Status() const;
void setHttp2Status(NetworkFactory::Http2Status status);

// Tries to guess feed hidden under given URL
// and uses given credentials.
// Returns pointer to guessed feed (if at least partially
Expand Down Expand Up @@ -140,6 +143,7 @@ class StandardFeed : public Feed {
QString m_lastEtag;
bool m_dontUseRawXmlSaving;
QVariantHash m_httpHeaders;
NetworkFactory::Http2Status m_http2Status;
};

Q_DECLARE_METATYPE(StandardFeed::SourceType)
Expand Down
5 changes: 3 additions & 2 deletions src/librssguard-standard/src/standardserviceroot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ QList<Message> StandardServiceRoot::obtainNewMessages(Feed* feed,
qDebugNN << "Using ETag value:" << QUOTE_W_SPACE_DOT(f->lastEtag());
}

auto network_result = NetworkFactory::performNetworkOperation(feed->source(),
auto network_result = NetworkFactory::performNetworkOperation(f->source(),
download_timeout,
{},
feed_contents,
Expand All @@ -229,7 +229,8 @@ QList<Message> StandardServiceRoot::obtainNewMessages(Feed* feed,
false,
{},
{},
networkProxy());
networkProxy(),
f->http2Status());

if (network_result.m_networkError != QNetworkReply::NetworkError::NoError) {
qWarningNN << LOGSEC_CORE << "Error" << QUOTE_W_SPACE(network_result.m_networkError)
Expand Down
24 changes: 24 additions & 0 deletions src/librssguard/network-web/basenetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ BaseNetworkAccessManager::BaseNetworkAccessManager(QObject* parent)
loadSettings();
}

void BaseNetworkAccessManager::setSpecificHtpp2Status(NetworkFactory::Http2Status status) {
switch (status) {
case NetworkFactory::Http2Status::DontSet:
m_enableHttp2 = qApp->settings()->value(GROUP(Network), SETTING(Network::EnableHttp2)).toBool();
break;

case NetworkFactory::Http2Status::Enabled:
m_enableHttp2 = true;
break;

case NetworkFactory::Http2Status::Disabled:
m_enableHttp2 = false;
break;
}
}

void BaseNetworkAccessManager::loadSettings() {
const QNetworkProxy::ProxyType selected_proxy_type =
static_cast<QNetworkProxy::ProxyType>(qApp->settings()->value(GROUP(Proxy), SETTING(Proxy::Type)).toInt());
Expand Down Expand Up @@ -66,6 +82,14 @@ QNetworkReply* BaseNetworkAccessManager::createRequest(QNetworkAccessManager::Op

#if QT_VERSION >= 0x050F00 // Qt >= 5.15.0
new_request.setAttribute(QNetworkRequest::Attribute::Http2AllowedAttribute, m_enableHttp2);

if (m_enableHttp2) {
qDebugNN << LOGSEC_NETWORK << "Enabling HTTP/2 for this network request.";
}
#endif

#if QT_VERSION >= 0x060300 // Qt >= 6.3.0
new_request.setAttribute(QNetworkRequest::Attribute::Http2CleartextAllowedAttribute, m_enableHttp2);
#endif

// new_request.setMaximumRedirectsAllowed(0);
Expand Down
4 changes: 4 additions & 0 deletions src/librssguard/network-web/basenetworkaccessmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#ifndef BASENETWORKACCESSMANAGER_H
#define BASENETWORKACCESSMANAGER_H

#include "network-web/networkfactory.h"

#include <QNetworkAccessManager>

// This is base class for all network access managers.
Expand All @@ -12,6 +14,8 @@ class BaseNetworkAccessManager : public QNetworkAccessManager {
public:
explicit BaseNetworkAccessManager(QObject* parent = nullptr);

void setSpecificHtpp2Status(NetworkFactory::Http2Status status);

public slots:
void loadSettings();

Expand Down
4 changes: 4 additions & 0 deletions src/librssguard/network-web/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ QUrl Downloader::lastUrl() const {
return m_lastUrl;
}

void Downloader::setHttp2Status(NetworkFactory::Http2Status status) {
m_downloadManager->setSpecificHtpp2Status(status);
}

QMap<QString, QString> Downloader::lastHeaders() const {
return m_lastHeaders;
}
Expand Down
2 changes: 2 additions & 0 deletions src/librssguard/network-web/downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "network-web/gemini/geminiclient.h"
#include "network-web/gemini/geminiparser.h"
#include "network-web/httpresponse.h"
#include "network-web/networkfactory.h"

#include <QHttpMultiPart>
#include <QNetworkProxy>
Expand Down Expand Up @@ -34,6 +35,7 @@ class Downloader : public QObject {
QMap<QString, QString> lastHeaders() const;
QUrl lastUrl() const;

void setHttp2Status(NetworkFactory::Http2Status status);
void setProxy(const QNetworkProxy& proxy);

public slots:
Expand Down
15 changes: 10 additions & 5 deletions src/librssguard/network-web/networkfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<IconLocatio
int timeout,
QPixmap& output,
const QList<QPair<QByteArray, QByteArray>>& additional_headers,
const QNetworkProxy& custom_proxy) {
const QNetworkProxy& custom_proxy,
Http2Status http2_status) {
QNetworkReply::NetworkError network_result = QNetworkReply::NetworkError::UnknownNetworkError;

for (const auto& url : urls) {
Expand Down Expand Up @@ -271,7 +272,8 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
bool protected_contents,
const QString& username,
const QString& password,
const QNetworkProxy& custom_proxy) {
const QNetworkProxy& custom_proxy,
Http2Status http2_status) {
Downloader downloader;
QEventLoop loop;
NetworkResult result;
Expand All @@ -289,6 +291,7 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
downloader.setProxy(custom_proxy);
}

downloader.setHttp2Status(http2_status);
downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password);
loop.exec();

Expand All @@ -301,7 +304,7 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
result.m_headers = downloader.lastHeaders();
result.m_url = downloader.lastUrl();

qDebugNN << LOGSEC_NETWORK << "URLS\n" << url << "\n" << result.m_url.toString();
qDebugNN << LOGSEC_NETWORK << "URLS\nRequest: " << url << "\nResponse: " << result.m_url.toString();

return result;
}
Expand All @@ -315,7 +318,8 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
bool protected_contents,
const QString& username,
const QString& password,
const QNetworkProxy& custom_proxy) {
const QNetworkProxy& custom_proxy,
Http2Status http2_status) {
Downloader downloader;
QEventLoop loop;
NetworkResult result;
Expand All @@ -333,6 +337,7 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
downloader.setProxy(custom_proxy);
}

downloader.setHttp2Status(http2_status);
downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password);
loop.exec();

Expand All @@ -345,7 +350,7 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
result.m_headers = downloader.lastHeaders();
result.m_url = downloader.lastUrl();

qDebugNN << LOGSEC_NETWORK << "URLS\n" << url << "\n" << result.m_url.toString();
qDebugNN << LOGSEC_NETWORK << "URLS\nRequest: " << url << "\nResponse: " << result.m_url.toString();

return result;
}
Expand Down
Loading

0 comments on commit c64b329

Please sign in to comment.