| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | // |
| 4 | // Copyright (C) 2011-2017 by Martin Rotter <[email protected]> |
| 5 | // Copyright (C) 2010-2014 by David Rosca <[email protected]> |
| 6 | // |
| 7 | // RSS Guard is free software: you can redistribute it and/or modify |
| 8 | // it under the terms of the GNU General Public License as published by |
| 9 | // the Free Software Foundation, either version 3 of the License, or |
| 10 | // (at your option) any later version. |
| 11 | // |
| 12 | // RSS Guard is distributed in the hope that it will be useful, |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | // GNU General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with RSS Guard. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | #include "network-web/webengine/networkurlinterceptor.h" |
| 21 | |
| 22 | #include "miscellaneous/application.h" |
| 23 | #include "miscellaneous/settings.h" |
| 24 | #include "network-web/webengine/urlinterceptor.h" |
| 25 | |
| 26 | NetworkUrlInterceptor::NetworkUrlInterceptor(QObject* parent) |
| 27 | : QWebEngineUrlRequestInterceptor(parent), m_sendDnt(false) {} |
| 28 | |
| 29 | void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { |
| 30 | if (m_sendDnt) { |
| 31 | info.setHttpHeader(QByteArrayLiteral("DNT"), QByteArrayLiteral("1")); |
| 32 | } |
| 33 | |
| 34 | // NOTE: Here we can add custom headers for each webengine request, for example "User-Agent". |
| 35 | |
| 36 | for (UrlInterceptor* interceptor : std::as_const(m_interceptors)) { |
| 37 | interceptor->interceptRequest(info); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void NetworkUrlInterceptor::installUrlInterceptor(UrlInterceptor* interceptor) { |
| 42 | if (!m_interceptors.contains(interceptor)) { |
| 43 | m_interceptors.append(interceptor); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void NetworkUrlInterceptor::removeUrlInterceptor(UrlInterceptor* interceptor) { |
| 48 | m_interceptors.removeOne(interceptor); |
| 49 | } |
| 50 | |
| 51 | void NetworkUrlInterceptor::load() { |
| 52 | m_sendDnt = qApp->settings()->value(GROUP(Network), SETTING(Network::SendDNT)).toBool(); |
| 53 | } |