From 4dcd7cf90bcf07fda00caa00252364541dc8ef1d Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Wed, 16 Aug 2017 00:28:23 +0300 Subject: [PATCH] core: Forward all non-local schemaless URLs via HTTPS. --- src/libs/core/networkaccessmanager.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libs/core/networkaccessmanager.cpp b/src/libs/core/networkaccessmanager.cpp index df1bd0a..4834855 100644 --- a/src/libs/core/networkaccessmanager.cpp +++ b/src/libs/core/networkaccessmanager.cpp @@ -35,10 +35,22 @@ QNetworkReply *NetworkAccessManager::createRequest(QNetworkAccessManager::Operat const QNetworkRequest &request, QIODevice *outgoingData) { - // Detect URLs without schema, and prevent them from being requested on a local filesytem. + static const QStringList localSchemes = {QStringLiteral("file"), QStringLiteral("qrc")}; + const QUrl url = request.url(); - if (url.scheme() == QLatin1String("file") && !url.host().isEmpty()) - return QNetworkAccessManager::createRequest(GetOperation, QNetworkRequest(), outgoingData); + + // Forward all non-local schemaless URLs via HTTPS. + if (localSchemes.contains(url.scheme()) && !url.host().isEmpty()) { + QUrl overrideUrl(url); + overrideUrl.setScheme(QStringLiteral("https")); + + QNetworkRequest overrideRequest(request); + overrideRequest.setUrl(overrideUrl); + + return QNetworkAccessManager::createRequest(GetOperation, overrideRequest, outgoingData); + } + + return QNetworkAccessManager::createRequest(op, request, outgoingData); }