aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/urlinterceptor.cpp
blob: 7e5630f82a830447b4170352fa3725b2ca6f720f (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
/*
 * 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 "formats/adblockrule.h"
#include <QDir>
#include <QJsonArray>
#include <QJsonDocument>
#include <QTextStream>
#include <boost/algorithm/string.hpp>
#include "configuration.h"
#include "filter.h"
#include "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)
{
    m_filter->filterRequest(info);

    // 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());
    }
}