aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/urlinterceptor.cpp
blob: cf9b85fb001a06002dd1ff68b0588e09560f2f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * This file is part of smolbote. It's copyrighted by the contributors recorded
 * in the version control history of the file, available from its original
 * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
 *
 * SPDX-License-Identifier: GPL-3.0
 */

#include "urlinterceptor.h"
#include "urlfilter/formats/adblockrule.h"
#include <QDir>
#include <QJsonArray>
#include <QJsonDocument>
#include <QTextStream>
#include <boost/algorithm/string.hpp>
#include <configuration/configuration.h>
#include "filter.h"
#include <web/webprofile.h>

// test DNT on https://browserleaks.com/donottrack

UrlRequestInterceptor::UrlRequestInterceptor(Filter* filter, WebProfile* profile, QObject* parent)
    : QWebEngineUrlRequestInterceptor(parent)
{
    Q_CHECK_PTR(filter);
    m_filter = filter;
    Q_CHECK_PTR(profile);
    m_profile = profile;
}

void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
    auto hostlistCheck = m_filter->hostlistRule(info.requestUrl().host());
    if(hostlistCheck) {
        info.block(hostlistCheck.value().isBlocking);
    }

    // set headers
    for(auto i = m_filter->headers().constBegin(); i != m_filter->headers().constEnd(); ++i) {
        info.setHttpHeader(i.key(), i.value());
    }
    for(auto i = m_profile->headers().constBegin(); i != m_profile->headers().constEnd(); ++i) {
        info.setHttpHeader(i.key(), i.value());
    }
}