aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/urlinterceptor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/urlinterceptor.cpp')
-rw-r--r--src/webengine/urlinterceptor.cpp20
1 files changed, 18 insertions, 2 deletions
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);
}