From d001ca63781072f9ec9d975da02588752f81b673 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 16 Dec 2021 09:44:42 +0100 Subject: [PATCH] use same UA for all network stuff in rss guard, also make UA to be more standard format --- pri/vars.pri | 2 +- resources/desktop/com.github.rssguard.appdata.xml | 2 +- src/librssguard/definitions/definitions.h | 6 ++++++ src/librssguard/network-web/basenetworkaccessmanager.cpp | 6 +++++- src/librssguard/network-web/cookiejar.h | 2 ++ src/librssguard/network-web/networkurlinterceptor.cpp | 5 +++++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pri/vars.pri b/pri/vars.pri index d3c589c4d..005e0e4ba 100644 --- a/pri/vars.pri +++ b/pri/vars.pri @@ -11,7 +11,7 @@ APP_URL = "https://github.com/martinrotter/rssguard" APP_URL_ISSUES = "https://github.com/martinrotter/rssguard/issues" APP_URL_ISSUES_NEW = "https://github.com/martinrotter/rssguard/issues/new" APP_URL_DOCUMENTATION = "https://github.com/martinrotter/rssguard/blob/master/resources/docs/Documentation.md" -APP_USERAGENT = "RSS Guard/$$APP_VERSION (github.com/martinrotter/rssguard)" +APP_USERAGENT = "RSS Guard/$$APP_VERSION" APP_DONATE_URL = "https://martinrotter.github.io/donate" message($$MSG_PREFIX: Welcome RSS Guard qmake script.) diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index ae258f422..30c77e7f2 100644 --- a/resources/desktop/com.github.rssguard.appdata.xml +++ b/resources/desktop/com.github.rssguard.appdata.xml @@ -26,7 +26,7 @@ https://github.com/sponsors/martinrotter - + none diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index 566306565..f786f5cd1 100644 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -143,6 +143,12 @@ #define DEFAULT_ZOOM_FACTOR 1.0f #define ZOOM_FACTOR_STEP 0.1f +#if defined(USE_WEBENGINE) +#define HTTP_COMPLETE_USERAGENT (QWebEngineProfile::defaultProfile()->httpUserAgent().toLocal8Bit() + QByteArrayLiteral(" ") + QByteArrayLiteral(APP_USERAGENT)) +#else +#define HTTP_COMPLETE_USERAGENT (QByteArrayLiteral(APP_USERAGENT)) +#endif + #define INTERNAL_URL_MESSAGE "http://rssguard.message" #define INTERNAL_URL_BLANK "http://rssguard.blank" #define INTERNAL_URL_ADBLOCKED "http://rssguard.adblocked" diff --git a/src/librssguard/network-web/basenetworkaccessmanager.cpp b/src/librssguard/network-web/basenetworkaccessmanager.cpp index c2e33eb5c..7dc6759b6 100644 --- a/src/librssguard/network-web/basenetworkaccessmanager.cpp +++ b/src/librssguard/network-web/basenetworkaccessmanager.cpp @@ -9,6 +9,10 @@ #include #include +#if defined(USE_WEBENGINE) +#include +#endif + BaseNetworkAccessManager::BaseNetworkAccessManager(QObject* parent) : QNetworkAccessManager(parent) { connect(this, &BaseNetworkAccessManager::sslErrors, this, &BaseNetworkAccessManager::onSslErrors); @@ -61,7 +65,7 @@ QNetworkReply* BaseNetworkAccessManager::createRequest(QNetworkAccessManager::Op #endif new_request.setRawHeader(HTTP_HEADERS_COOKIE, QSL("JSESSIONID= ").toLocal8Bit()); - new_request.setRawHeader(HTTP_HEADERS_USER_AGENT, QSL(APP_USERAGENT).toLocal8Bit()); + new_request.setRawHeader(HTTP_HEADERS_USER_AGENT, HTTP_COMPLETE_USERAGENT); auto reply = QNetworkAccessManager::createRequest(op, new_request, outgoingData); return reply; diff --git a/src/librssguard/network-web/cookiejar.h b/src/librssguard/network-web/cookiejar.h index cfe9f57d8..8b6507e39 100644 --- a/src/librssguard/network-web/cookiejar.h +++ b/src/librssguard/network-web/cookiejar.h @@ -14,6 +14,8 @@ class CookieJar : public QNetworkCookieJar { virtual bool insertCookie(const QNetworkCookie& cookie); virtual bool updateCookie(const QNetworkCookie& cookie); virtual bool deleteCookie(const QNetworkCookie& cookie); + + public: static QList extractCookiesFromUrl(const QString& url); private: diff --git a/src/librssguard/network-web/networkurlinterceptor.cpp b/src/librssguard/network-web/networkurlinterceptor.cpp index 6d668cdc8..871d0153e 100644 --- a/src/librssguard/network-web/networkurlinterceptor.cpp +++ b/src/librssguard/network-web/networkurlinterceptor.cpp @@ -23,6 +23,8 @@ #include "miscellaneous/settings.h" #include "network-web/urlinterceptor.h" +#include + NetworkUrlInterceptor::NetworkUrlInterceptor(QObject* parent) : QWebEngineUrlRequestInterceptor(parent), m_sendDnt(false) {} @@ -33,6 +35,9 @@ void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { // NOTE: Here we can add custom headers for each webengine request, for example "User-Agent". + info.setHttpHeader(QByteArrayLiteral(HTTP_HEADERS_USER_AGENT), + HTTP_COMPLETE_USERAGENT); + for (UrlInterceptor* interceptor : qAsConst(m_interceptors)) { interceptor->interceptRequest(info); }