From 2a5ea0269a1f9511c51d661a6c7d7bdc7d0176fa Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 7 Oct 2018 13:20:54 +0200 Subject: Expand HTTP header settings #4 - add doc/Usage/Filter.asciidoc to explain the usage of the filter headers - add HTTP headers to Profile (section "headers") - Use request interceptor to apply filter headers, then profile headers - add insert/delete actions to ProfileEditor --- lib/web/profilemanager.cpp | 13 +++++++++++++ lib/web/webprofile.cpp | 14 ++++++++++++++ lib/web/webprofile.h | 9 +++++++++ 3 files changed, 36 insertions(+) (limited to 'lib/web') diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp index 74ddc75..17435e8 100644 --- a/lib/web/profilemanager.cpp +++ b/lib/web/profilemanager.cpp @@ -73,6 +73,19 @@ WebProfile *ProfileManager::loadProfile(const QString &path) this->m_profiles.at(id)->settings.setValue("attributes/" + QString::number(attr), value); }); + // headers + ptr->settings.beginGroup("headers"); + for(const QString &key : ptr->settings.childKeys()) { + ptr->profile->setHttpHeader(key.toLatin1(), ptr->settings.value(key).toString().toLatin1()); + } + ptr->settings.endGroup(); + connect(ptr->profile, &WebProfile::headerChanged, ptr->profile, [this, id](const QString &name, const QString &value) { + this->m_profiles.at(id)->settings.setValue("headers/" + name, value); + }); + connect(ptr->profile, &WebProfile::headerRemoved, ptr->profile, [this, id](const QString &name) { + this->m_profiles.at(id)->settings.remove("headers/" + name); + }); + m_profiles[id] = std::move(ptr); return m_profiles.at(id)->profile; } diff --git a/lib/web/webprofile.cpp b/lib/web/webprofile.cpp index bd84d38..16c12b7 100644 --- a/lib/web/webprofile.cpp +++ b/lib/web/webprofile.cpp @@ -135,6 +135,20 @@ void WebProfile::setHttpUserAgent(const QString &userAgent) emit propertyChanged("httpUserAgent", userAgent); } +void WebProfile::setHttpHeader(const QString& name, const QString& value) +{ + m_headers[name.toLatin1()] = value.toLatin1(); + emit headerChanged(name, value); +} + +void WebProfile::removeHttpHeader(const QString& name) +{ + if(m_headers.contains(name.toLatin1())) { + m_headers.remove(name.toLatin1()); + emit headerRemoved(name); + } +} + void WebProfile::setSpellCheckEnabled(bool enable) { QWebEngineProfile::setSpellCheckEnabled(enable); diff --git a/lib/web/webprofile.h b/lib/web/webprofile.h index b58fad7..269989b 100644 --- a/lib/web/webprofile.h +++ b/lib/web/webprofile.h @@ -65,6 +65,10 @@ public: { return qAsConst(m_cookies); } + const QMap headers() const + { + return qAsConst(m_headers); + } // search url QString search() const; @@ -86,6 +90,8 @@ public: void setHttpCacheMaximumSize(int maxSize); void setHttpCacheType(int type); void setHttpUserAgent(const QString &userAgent); + void setHttpHeader(const QString &name, const QString &value); + void removeHttpHeader(const QString &name); void setSpellCheckEnabled(bool enable); @@ -97,6 +103,8 @@ signals: void propertyChanged(const QString &name, const QVariant &value); void attributeChanged(const QWebEngineSettings::WebAttribute attribute, const bool value); + void headerChanged(const QString &name, const QString &value); + void headerRemoved(const QString &name); private: static WebProfile *profile; @@ -107,6 +115,7 @@ private: QUrl m_newtab = QUrl("about:blank"); QVector m_cookies; + QMap m_headers; }; #endif // SMOLBOTE_WEBENGINEPROFILE_H -- cgit v1.2.1