use same UA for all network stuff in rss guard, also make UA to be more standard format
This commit is contained in:
		
							parent
							
								
									7cf80321bd
								
							
						
					
					
						commit
						d001ca6378
					
				
					 6 changed files with 20 additions and 3 deletions
				
			
		|  | @ -11,7 +11,7 @@ APP_URL                       = "https://github.com/martinrotter/rssguard" | ||||||
| APP_URL_ISSUES                = "https://github.com/martinrotter/rssguard/issues" | APP_URL_ISSUES                = "https://github.com/martinrotter/rssguard/issues" | ||||||
| APP_URL_ISSUES_NEW            = "https://github.com/martinrotter/rssguard/issues/new" | 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_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" | APP_DONATE_URL                = "https://martinrotter.github.io/donate" | ||||||
| 
 | 
 | ||||||
| message($$MSG_PREFIX: Welcome RSS Guard qmake script.) | message($$MSG_PREFIX: Welcome RSS Guard qmake script.) | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ | ||||||
|   <url type="donation">https://github.com/sponsors/martinrotter</url> |   <url type="donation">https://github.com/sponsors/martinrotter</url> | ||||||
|   <content_rating type="oars-1.1" /> |   <content_rating type="oars-1.1" /> | ||||||
|   <releases> |   <releases> | ||||||
|     <release version="4.0.4" date="2021-12-15"/> |     <release version="4.0.4" date="2021-12-16"/> | ||||||
|   </releases> |   </releases> | ||||||
|   <content_rating type="oars-1.0"> |   <content_rating type="oars-1.0"> | ||||||
|     <content_attribute id="violence-cartoon">none</content_attribute> |     <content_attribute id="violence-cartoon">none</content_attribute> | ||||||
|  |  | ||||||
|  | @ -143,6 +143,12 @@ | ||||||
| #define DEFAULT_ZOOM_FACTOR 1.0f | #define DEFAULT_ZOOM_FACTOR 1.0f | ||||||
| #define ZOOM_FACTOR_STEP    0.1f | #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_MESSAGE                  "http://rssguard.message"
 | ||||||
| #define INTERNAL_URL_BLANK                    "http://rssguard.blank"
 | #define INTERNAL_URL_BLANK                    "http://rssguard.blank"
 | ||||||
| #define INTERNAL_URL_ADBLOCKED                "http://rssguard.adblocked"
 | #define INTERNAL_URL_ADBLOCKED                "http://rssguard.adblocked"
 | ||||||
|  |  | ||||||
|  | @ -9,6 +9,10 @@ | ||||||
| #include <QNetworkReply> | #include <QNetworkReply> | ||||||
| #include <QNetworkRequest> | #include <QNetworkRequest> | ||||||
| 
 | 
 | ||||||
|  | #if defined(USE_WEBENGINE) | ||||||
|  | #include <QWebEngineProfile> | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| BaseNetworkAccessManager::BaseNetworkAccessManager(QObject* parent) | BaseNetworkAccessManager::BaseNetworkAccessManager(QObject* parent) | ||||||
|   : QNetworkAccessManager(parent) { |   : QNetworkAccessManager(parent) { | ||||||
|   connect(this, &BaseNetworkAccessManager::sslErrors, this, &BaseNetworkAccessManager::onSslErrors); |   connect(this, &BaseNetworkAccessManager::sslErrors, this, &BaseNetworkAccessManager::onSslErrors); | ||||||
|  | @ -61,7 +65,7 @@ QNetworkReply* BaseNetworkAccessManager::createRequest(QNetworkAccessManager::Op | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|   new_request.setRawHeader(HTTP_HEADERS_COOKIE, QSL("JSESSIONID= ").toLocal8Bit()); |   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); |   auto reply = QNetworkAccessManager::createRequest(op, new_request, outgoingData); | ||||||
|   return reply; |   return reply; | ||||||
|  |  | ||||||
|  | @ -14,6 +14,8 @@ class CookieJar : public QNetworkCookieJar { | ||||||
|     virtual bool insertCookie(const QNetworkCookie& cookie); |     virtual bool insertCookie(const QNetworkCookie& cookie); | ||||||
|     virtual bool updateCookie(const QNetworkCookie& cookie); |     virtual bool updateCookie(const QNetworkCookie& cookie); | ||||||
|     virtual bool deleteCookie(const QNetworkCookie& cookie); |     virtual bool deleteCookie(const QNetworkCookie& cookie); | ||||||
|  | 
 | ||||||
|  |   public: | ||||||
|     static QList<QNetworkCookie> extractCookiesFromUrl(const QString& url); |     static QList<QNetworkCookie> extractCookiesFromUrl(const QString& url); | ||||||
| 
 | 
 | ||||||
|   private: |   private: | ||||||
|  |  | ||||||
|  | @ -23,6 +23,8 @@ | ||||||
| #include "miscellaneous/settings.h" | #include "miscellaneous/settings.h" | ||||||
| #include "network-web/urlinterceptor.h" | #include "network-web/urlinterceptor.h" | ||||||
| 
 | 
 | ||||||
|  | #include <QWebEngineProfile> | ||||||
|  | 
 | ||||||
| NetworkUrlInterceptor::NetworkUrlInterceptor(QObject* parent) | NetworkUrlInterceptor::NetworkUrlInterceptor(QObject* parent) | ||||||
|   : QWebEngineUrlRequestInterceptor(parent), m_sendDnt(false) {} |   : 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".
 |   // 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)) { |   for (UrlInterceptor* interceptor : qAsConst(m_interceptors)) { | ||||||
|     interceptor->interceptRequest(info); |     interceptor->interceptRequest(info); | ||||||
|   } |   } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue