From 6e984feb38379f19fa5f2d924201db681f87d1ac Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sat, 1 Apr 2023 09:15:07 +0800 Subject: [PATCH] set Origin header --- weburlrequestinterceptor.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/weburlrequestinterceptor.cpp b/weburlrequestinterceptor.cpp index 6d512e2b..384c09ff 100644 --- a/weburlrequestinterceptor.cpp +++ b/weburlrequestinterceptor.cpp @@ -3,32 +3,31 @@ #include "utils.hh" #include "globalbroadcaster.h" -WebUrlRequestInterceptor::WebUrlRequestInterceptor(QObject *p) - :QWebEngineUrlRequestInterceptor(p) +WebUrlRequestInterceptor::WebUrlRequestInterceptor( QObject * p ): + QWebEngineUrlRequestInterceptor( p ) +{ +} +void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo & info ) { -} -void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info) { - info.setHttpHeader("origin",Utils::Url::getHostBaseFromUrl(info.requestUrl()).toUtf8()); - info.setHttpHeader("referer",info.requestUrl().url().toUtf8()); - if( GlobalBroadcaster::instance()->getPreference()->disallowContentFromOtherSites && Utils::isExternalLink( info.requestUrl() ) ) - { + info.setHttpHeader( "origin", "*" ); + info.setHttpHeader( "referer", info.requestUrl().url().toUtf8() ); + if ( GlobalBroadcaster::instance()->getPreference()->disallowContentFromOtherSites + && Utils::isExternalLink( info.requestUrl() ) ) { //file:// link ,pass - if(info.requestUrl().scheme()=="file"){ + if ( info.requestUrl().scheme() == "file" ) { return; } auto hostBase = Utils::Url::getHostBase( info.requestUrl().host() ); - if( GlobalBroadcaster::instance()->existedInWhitelist( hostBase ) ) - { + if ( GlobalBroadcaster::instance()->existedInWhitelist( hostBase ) ) { //whitelist url does not block return; } - if( info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage - || info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeFontResource - || info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeStylesheet - || info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMedia - || Utils::isHtmlResources( info.requestUrl() ) ) - { + if ( info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage + || info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeFontResource + || info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeStylesheet + || info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMedia + || Utils::isHtmlResources( info.requestUrl() ) ) { //let throuth the resources file. return; }