aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-07-05 12:13:08 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-07-05 12:13:08 +0200
commita6bd5a227ecccba76d2486c5a4d6408770e1bcec (patch)
treea7e754238342651c531d101db9bf745526a230e5 /src
parentUpdate translations (diff)
downloadsmolbote-a6bd5a227ecccba76d2486c5a4d6408770e1bcec.tar.xz
Add filter.header
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp2
-rw-r--r--src/webengine/urlinterceptor.cpp20
-rw-r--r--src/webengine/urlinterceptor.h9
3 files changed, 27 insertions, 4 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index f056525..29eaea5 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -102,7 +102,7 @@ void Browser::setup(const QString &defaultProfile)
// downloads
m_downloads = std::make_unique<DownloadsWidget>(m_config->value<QString>("downloads.path").value());
// url request filter
- m_urlFilter = std::make_unique<UrlRequestInterceptor>(m_config->value<QString>("filter.path").value());
+ m_urlFilter = std::make_unique<UrlRequestInterceptor>(m_config);
// cookie request filter
// load profiles
diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp
index 4fc23e0..70d7701 100644
--- a/src/webengine/urlinterceptor.cpp
+++ b/src/webengine/urlinterceptor.cpp
@@ -9,11 +9,13 @@
#include "urlinterceptor.h"
#include <QDir>
#include <QTextStream>
+#include <configuration/configuration.h>
+#include <boost/algorithm/string.hpp>
-UrlRequestInterceptor::UrlRequestInterceptor(const QString &path, QObject *parent)
+UrlRequestInterceptor::UrlRequestInterceptor(const std::unique_ptr<Configuration> &config, QObject *parent)
: QWebEngineUrlRequestInterceptor(parent)
{
- QDir hostsD(path);
+ QDir hostsD(config->value<QString>("filter.path").value());
const QStringList hostFiles = hostsD.entryList(QDir::Files);
for(const QString &file : hostFiles) {
const QString absPath = hostsD.absoluteFilePath(file);
@@ -24,10 +26,24 @@ UrlRequestInterceptor::UrlRequestInterceptor(const QString &path, QObject *paren
rules.unite(r);
}
+
+ const auto header = config->value<std::vector<std::string>>("filter.header");
+ if(header) {
+ for(const std::string &h : header.value()) {
+ std::vector<std::string> s;
+ boost::split(s, h, boost::is_any_of(":="));
+ auto pair = std::make_pair(s.at(0), s.at(1));
+ m_headers.emplace_back(pair);
+ }
+ }
}
void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
+ for(const Header &header : m_headers) {
+ info.setHttpHeader(QByteArray::fromStdString(header.first), QByteArray::fromStdString(header.second));
+ }
+
if(rules.contains(info.requestUrl().host())) {
info.block(rules.value(info.requestUrl().host()).isBlocking);
}
diff --git a/src/webengine/urlinterceptor.h b/src/webengine/urlinterceptor.h
index 2a5c50d..2f91e30 100644
--- a/src/webengine/urlinterceptor.h
+++ b/src/webengine/urlinterceptor.h
@@ -10,7 +10,13 @@
#define URLREQUESTINTERCEPTOR_H
#include <QWebEngineUrlRequestInterceptor>
+#include <memory>
+#include <QVector>
+#include <QByteArray>
+typedef std::pair<std::string, std::string> Header;
+
+class Configuration;
class UrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
{
Q_OBJECT
@@ -19,13 +25,14 @@ public:
bool isBlocking;
};
- explicit UrlRequestInterceptor(const QString &path, QObject *parent = nullptr);
+ explicit UrlRequestInterceptor(const std::unique_ptr<Configuration> &config, QObject *parent = nullptr);
~UrlRequestInterceptor() = default;
void interceptRequest(QWebEngineUrlRequestInfo &info) override;
private:
QHash<QString, HostRule> rules;
+ std::vector<Header> m_headers;
};
QHash<QString, UrlRequestInterceptor::HostRule> parse(const QString &filename);