fixed #835
This commit is contained in:
parent
3169d753fb
commit
a3eeb4419e
@ -118,6 +118,9 @@
|
||||
#define CLI_SIN_SHORT "s"
|
||||
#define CLI_SIN_LONG "no-single-instance"
|
||||
|
||||
#define CLI_USERAGENT_SHORT "u"
|
||||
#define CLI_USERAGENT_LONG "user-agent"
|
||||
|
||||
#define CLI_ADBLOCKPORT_SHORT "p"
|
||||
#define CLI_ADBLOCKPORT_LONG "adblock-port"
|
||||
|
||||
|
@ -63,7 +63,10 @@
|
||||
|
||||
Application::Application(const QString& id, int& argc, char** argv, const QStringList& raw_cli_args)
|
||||
: SingleApplication(id, argc, argv), m_rawCliArgs(raw_cli_args), m_updateFeedsLock(new Mutex()) {
|
||||
parseCmdArgumentsFromMyInstance(raw_cli_args);
|
||||
QString custom_ua;
|
||||
|
||||
parseCmdArgumentsFromMyInstance(raw_cli_args, custom_ua);
|
||||
|
||||
qInstallMessageHandler(performLogging);
|
||||
|
||||
m_feedReader = nullptr;
|
||||
@ -156,6 +159,8 @@ Application::Application(const QString& id, int& argc, char** argv, const QStrin
|
||||
}
|
||||
#endif
|
||||
|
||||
m_webFactory->setCustomUserAgent(custom_ua);
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
m_webFactory->urlIinterceptor()->load();
|
||||
|
||||
@ -164,7 +169,13 @@ Application::Application(const QString& id, int& argc, char** argv, const QStrin
|
||||
m_webFactory->engineProfile()->setCachePath(web_data_root + QDir::separator() + QSL("cache"));
|
||||
m_webFactory->engineProfile()->setHttpCacheType(QWebEngineProfile::HttpCacheType::DiskHttpCache);
|
||||
m_webFactory->engineProfile()->setPersistentStoragePath(web_data_root + QDir::separator() + QSL("storage"));
|
||||
m_webFactory->engineProfile()->setHttpUserAgent(QString(HTTP_COMPLETE_USERAGENT));
|
||||
|
||||
if (custom_ua.isEmpty()) {
|
||||
m_webFactory->engineProfile()->setHttpUserAgent(QString(HTTP_COMPLETE_USERAGENT));
|
||||
}
|
||||
else {
|
||||
m_webFactory->engineProfile()->setHttpUserAgent(custom_ua);
|
||||
}
|
||||
|
||||
qDebugNN << LOGSEC_NETWORK << "Persistent web data storage path:"
|
||||
<< QUOTE_W_SPACE_DOT(m_webFactory->engineProfile()->persistentStoragePath());
|
||||
@ -1004,7 +1015,7 @@ void Application::parseCmdArgumentsFromOtherInstance(const QString& message) {
|
||||
}
|
||||
}
|
||||
|
||||
void Application::parseCmdArgumentsFromMyInstance(const QStringList& raw_cli_args) {
|
||||
void Application::parseCmdArgumentsFromMyInstance(const QStringList& raw_cli_args, QString& custom_ua) {
|
||||
fillCmdArgumentsParser(m_cmdParser);
|
||||
|
||||
m_cmdParser.setApplicationDescription(QSL(APP_NAME));
|
||||
@ -1073,6 +1084,8 @@ void Application::parseCmdArgumentsFromMyInstance(const QStringList& raw_cli_arg
|
||||
else {
|
||||
m_customAdblockPort = 0;
|
||||
}
|
||||
|
||||
custom_ua = m_cmdParser.value(QSL(CLI_USERAGENT_SHORT));
|
||||
}
|
||||
|
||||
void Application::displayLog() {
|
||||
@ -1115,6 +1128,10 @@ void Application::fillCmdArgumentsParser(QCommandLineParser& parser) {
|
||||
QCommandLineOption forced_style({QSL(CLI_STYLE_SHORT), QSL(CLI_STYLE_LONG)},
|
||||
QSL("Force some application style."),
|
||||
QSL("style-name"));
|
||||
|
||||
QCommandLineOption custom_ua({QSL(CLI_USERAGENT_SHORT), QSL(CLI_USERAGENT_LONG)},
|
||||
QSL("User custom User-Agent HTTP header for all network requests."),
|
||||
QSL("user-agent"));
|
||||
QCommandLineOption
|
||||
adblock_port({QSL(CLI_ADBLOCKPORT_SHORT), QSL(CLI_ADBLOCKPORT_LONG)},
|
||||
QSL("Use custom port for AdBlock server. It is highly recommended to use values higher than 1024."),
|
||||
@ -1125,7 +1142,7 @@ void Application::fillCmdArgumentsParser(QCommandLineParser& parser) {
|
||||
#if defined(USE_WEBENGINE)
|
||||
force_nowebengine,
|
||||
#endif
|
||||
forced_style, adblock_port
|
||||
forced_style, adblock_port, custom_ua
|
||||
});
|
||||
parser.addPositionalArgument(QSL("urls"),
|
||||
QSL("List of URL addresses pointing to individual online feeds which should be added."),
|
||||
|
@ -187,7 +187,7 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
|
||||
|
||||
// Processes incoming message from another RSS Guard instance.
|
||||
void parseCmdArgumentsFromOtherInstance(const QString& message);
|
||||
void parseCmdArgumentsFromMyInstance(const QStringList& raw_cli_args);
|
||||
void parseCmdArgumentsFromMyInstance(const QStringList& raw_cli_args, QString &custom_ua);
|
||||
|
||||
void displayLog();
|
||||
|
||||
|
@ -62,7 +62,15 @@ QNetworkReply* BaseNetworkAccessManager::createRequest(QNetworkAccessManager::Op
|
||||
#endif
|
||||
|
||||
new_request.setRawHeader(HTTP_HEADERS_COOKIE, QSL("JSESSIONID= ").toLocal8Bit());
|
||||
new_request.setRawHeader(HTTP_HEADERS_USER_AGENT, HTTP_COMPLETE_USERAGENT);
|
||||
|
||||
auto custom_ua = qApp->web()->customUserAgent();
|
||||
|
||||
if (custom_ua.isEmpty()) {
|
||||
new_request.setRawHeader(HTTP_HEADERS_USER_AGENT, HTTP_COMPLETE_USERAGENT);
|
||||
}
|
||||
else {
|
||||
new_request.setRawHeader(HTTP_HEADERS_USER_AGENT, custom_ua.toLocal8Bit());
|
||||
}
|
||||
|
||||
auto reply = QNetworkAccessManager::createRequest(op, new_request, outgoingData);
|
||||
return reply;
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <QWebEngineUrlScheme>
|
||||
#endif
|
||||
|
||||
WebFactory::WebFactory(QObject* parent) : QObject(parent) {
|
||||
WebFactory::WebFactory(QObject* parent) : QObject(parent), m_customUserAgent(QString()) {
|
||||
m_adBlock = new AdBlockManager(this);
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
@ -657,3 +657,11 @@ void WebFactory::generateUnescapes() {
|
||||
m_htmlNamedEntities[QSL("zwj")] = 0x200d;
|
||||
m_htmlNamedEntities[QSL("zwnj")] = 0x200c;
|
||||
}
|
||||
|
||||
QString WebFactory::customUserAgent() const {
|
||||
return m_customUserAgent;
|
||||
}
|
||||
|
||||
void WebFactory::setCustomUserAgent(const QString& user_agent) {
|
||||
m_customUserAgent = user_agent;
|
||||
}
|
||||
|
@ -56,6 +56,9 @@ class WebFactory : public QObject {
|
||||
bool sendMessageViaEmail(const Message& message);
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
QString customUserAgent() const;
|
||||
void setCustomUserAgent(const QString& user_agent);
|
||||
|
||||
private slots:
|
||||
void createMenu(QMenu* menu = nullptr);
|
||||
void webEngineSettingChanged(bool enabled);
|
||||
@ -79,6 +82,7 @@ class WebFactory : public QObject {
|
||||
CookieJar* m_cookieJar;
|
||||
Readability* m_readability;
|
||||
QMap<QString, char16_t> m_htmlNamedEntities;
|
||||
QString m_customUserAgent;
|
||||
};
|
||||
|
||||
#endif // WEBFACTORY_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user