This commit is contained in:
Martin Rotter 2025-01-29 10:18:18 +01:00
parent f5038d539a
commit c64b3291d3
16 changed files with 157 additions and 33 deletions

View file

@ -16,7 +16,6 @@
class RootItem;
class GmailServiceRoot;
class OAuth2Service;
class Downloader;
class GmailNetworkFactory : public QObject {
Q_OBJECT

View file

@ -14,7 +14,6 @@
class RootItem;
class RedditServiceRoot;
class OAuth2Service;
class Downloader;
struct Subreddit {};

View file

@ -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({});
@ -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.
@ -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())));
}
}

View file

@ -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)));
}

View file

@ -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>
@ -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>

View file

@ -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) {
@ -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() {
@ -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"
@ -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;
}
@ -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;
}
@ -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) {

View file

@ -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
@ -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)

View file

@ -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,
@ -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)

View file

@ -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());
@ -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);

View file

@ -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.
@ -12,6 +14,8 @@ class BaseNetworkAccessManager : public QNetworkAccessManager {
public:
explicit BaseNetworkAccessManager(QObject* parent = nullptr);
void setSpecificHtpp2Status(NetworkFactory::Http2Status status);
public slots:
void loadSettings();

View file

@ -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;
}

View file

@ -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>
@ -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:

View file

@ -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) {
@ -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;
@ -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();
@ -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;
}
@ -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;
@ -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();
@ -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;
}

View file

@ -5,7 +5,6 @@
#include "definitions/typedefs.h"
#include "network-web/httpresponse.h"
#include "services/abstract/feed.h"
#include <QCoreApplication>
#include <QHttpPart>
@ -30,8 +29,6 @@ struct RSSGUARD_DLLSPEC NetworkResult {
const QList<QNetworkCookie>& cook);
};
class Downloader;
class RSSGUARD_DLLSPEC NetworkFactory {
Q_DECLARE_TR_FUNCTIONS(NetworkFactory)
@ -45,6 +42,12 @@ class RSSGUARD_DLLSPEC NetworkFactory {
Token = 2
};
enum class Http2Status {
DontSet = 0, // Use application-wide setting.
Enabled = 1,
Disabled = 2
};
static QStringList extractFeedLinksFromHtmlPage(const QUrl& url, const QString& html);
static QPair<QByteArray, QByteArray> generateBasicAuthHeader(NetworkAuthentication protection,
const QString& username,
@ -61,7 +64,8 @@ class RSSGUARD_DLLSPEC NetworkFactory {
QPixmap& output,
const QList<QPair<QByteArray, QByteArray>>& additional_headers,
const QNetworkProxy& custom_proxy =
QNetworkProxy::ProxyType::DefaultProxy);
QNetworkProxy::ProxyType::DefaultProxy,
Http2Status http2_status = Http2Status::DontSet);
static NetworkResult performNetworkOperation(const QString& url,
int timeout,
const QByteArray& input_data,
@ -73,7 +77,8 @@ class RSSGUARD_DLLSPEC NetworkFactory {
const QString& username = QString(),
const QString& password = QString(),
const QNetworkProxy& custom_proxy =
QNetworkProxy::ProxyType::DefaultProxy);
QNetworkProxy::ProxyType::DefaultProxy,
Http2Status http2_status = Http2Status::DontSet);
static NetworkResult performNetworkOperation(const QString& url,
int timeout,
QHttpMultiPart* input_data,
@ -85,7 +90,8 @@ class RSSGUARD_DLLSPEC NetworkFactory {
const QString& username = QString(),
const QString& password = QString(),
const QNetworkProxy& custom_proxy =
QNetworkProxy::ProxyType::DefaultProxy);
QNetworkProxy::ProxyType::DefaultProxy,
Http2Status http2_status = Http2Status::DontSet);
};
Q_DECLARE_METATYPE(NetworkFactory::NetworkAuthentication)

View file

@ -61,7 +61,7 @@ void FormFeedDetails::apply() {
}
if (isChangeAllowed(m_ui->m_mcbFeedRtl)) {
fd->setIsRtl(m_ui->m_cbFeedRTL->isChecked());
fd->setIsRtl(m_ui->m_cbFeedRtl->isChecked());
}
m_ui->m_wdgArticleLimiting->saveFeed(fd, m_isBatchEdit);
@ -127,7 +127,7 @@ void FormFeedDetails::loadFeedData() {
m_ui->m_mcbOpenArticlesAutomatically->addActionWidget(m_ui->m_cbOpenArticlesAutomatically);
m_ui->m_mcbDisableFeed->addActionWidget(m_ui->m_cbDisableFeed);
m_ui->m_mcbSuppressFeed->addActionWidget(m_ui->m_cbSuppressFeed);
m_ui->m_mcbFeedRtl->addActionWidget(m_ui->m_cbFeedRTL);
m_ui->m_mcbFeedRtl->addActionWidget(m_ui->m_cbFeedRtl);
}
else {
// We hide batch selectors.
@ -158,7 +158,7 @@ void FormFeedDetails::loadFeedData() {
->setCurrentIndex(m_ui->m_cmbAutoUpdateType->findData(QVariant::fromValue(int(fd->autoUpdateType()))));
m_ui->m_spinAutoUpdateInterval->setValue(fd->autoUpdateInterval());
m_ui->m_cbOpenArticlesAutomatically->setChecked(fd->openArticlesDirectly());
m_ui->m_cbFeedRTL->setChecked(fd->isRtl());
m_ui->m_cbFeedRtl->setChecked(fd->isRtl());
m_ui->m_cbDisableFeed->setChecked(fd->isSwitchedOff());
m_ui->m_cbSuppressFeed->setChecked(fd->isQuiet());

View file

@ -131,7 +131,7 @@
<widget class="MultiFeedEditCheckBox" name="m_mcbFeedRtl"/>
</item>
<item>
<widget class="QCheckBox" name="m_cbFeedRTL">
<widget class="QCheckBox" name="m_cbFeedRtl">
<property name="text">
<string>Right-to-left layout</string>
</property>
@ -146,10 +146,10 @@
<item>
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
<property name="centerButtons">
<bool>false</bool>
@ -177,10 +177,18 @@
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_tabWidget</tabstop>
<tabstop>m_mcbAutoDownloading</tabstop>
<tabstop>m_cmbAutoUpdateType</tabstop>
<tabstop>m_spinAutoUpdateInterval</tabstop>
<tabstop>m_mcbOpenArticlesAutomatically</tabstop>
<tabstop>m_cbOpenArticlesAutomatically</tabstop>
<tabstop>m_mcbSuppressFeed</tabstop>
<tabstop>m_cbSuppressFeed</tabstop>
<tabstop>m_mcbDisableFeed</tabstop>
<tabstop>m_cbDisableFeed</tabstop>
<tabstop>m_cbFeedRTL</tabstop>
<tabstop>m_mcbFeedRtl</tabstop>
<tabstop>m_cbFeedRtl</tabstop>
</tabstops>
<resources/>
<connections>