From b456c18bf62b8f806d36f4968befafffbbc276b6 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sun, 17 Nov 2024 00:16:13 +0100 Subject: [PATCH] Fix KIO scheme handler BUG: 491247 Signed-off-by: Juraj Oravec --- .../kioschemehandler.cpp | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/plugins/KDEFrameworksIntegration/kioschemehandler.cpp b/src/plugins/KDEFrameworksIntegration/kioschemehandler.cpp index 3021e3919..58641da0c 100644 --- a/src/plugins/KDEFrameworksIntegration/kioschemehandler.cpp +++ b/src/plugins/KDEFrameworksIntegration/kioschemehandler.cpp @@ -22,10 +22,8 @@ #include #include -#include +#include -#include -Q_GLOBAL_STATIC_WITH_ARGS(QNetworkAccessManager, s_knam, (nullptr)) KIOSchemeHandler::KIOSchemeHandler(const QString &protocol, QObject *parent) : QWebEngineUrlSchemeHandler(parent) @@ -47,19 +45,30 @@ void KIOSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) } QPointer jobPtr = job; - QNetworkReply *reply = s_knam()->get(QNetworkRequest(job->requestUrl())); - connect(reply, &QNetworkReply::finished, this, [=]() { + + KIO::StoredTransferJob *kioJob = KIO::storedGet(job->requestUrl(), KIO::NoReload, + KIO::HideProgressInfo); + kioJob->setRedirectionHandlingEnabled(false); + connect(kioJob, &KIO::StoredTransferJob::result, this, [=]() { + kioJob->deleteLater(); if (!jobPtr) { - reply->deleteLater(); return; } - if (reply->error() != QNetworkReply::NoError) { - reply->deleteLater(); - qWarning() << "Error:" << reply->errorString(); + + if (kioJob->error() == KJob::NoError) { + if (kioJob->redirectUrl().isValid()) { + job->redirect(kioJob->redirectUrl()); + } else { + QBuffer *buffer = new QBuffer; + buffer->open(QBuffer::ReadWrite); + buffer->write(kioJob->data()); + buffer->seek(0); + connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater); + job->reply(kioJob->mimetype().toUtf8(), buffer); + } + } + else { job->fail(QWebEngineUrlRequestJob::RequestFailed); - } else { - reply->setParent(job); - job->reply(reply->header(QNetworkRequest::ContentTypeHeader).toByteArray(), reply); } }); }