From 4849b5e364272d856185c8da65da7cf1311d7903 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 17 Jul 2018 11:19:43 +0200 Subject: [PATCH] Rewrite the request interceptor. It seems that there are request in the form "blob://foo.zim/". I don't know where it come from, we cannot handle it and even Qt is parsing it wrongly (scheme and host are empty, path is the full url request). By using a string to handle the url, it is simpler to change "http://" to "zim://". --- kiwixrequestinterceptor.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kiwixrequestinterceptor.cpp b/kiwixrequestinterceptor.cpp index 53af39f..31da7b3 100644 --- a/kiwixrequestinterceptor.cpp +++ b/kiwixrequestinterceptor.cpp @@ -14,10 +14,12 @@ void KiwixRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { std::cout << "Intercept request" << std::endl; auto url = info.requestUrl(); - std::cout << " - " << url.toString().toUtf8().constData() << std::endl; - url.setScheme("zim"); - std::cout << " + " << url.toString().toUtf8().constData() << std::endl; - info.redirect(url); - + auto urlString = url.toString(); + std::cout << " - " << urlString.toUtf8().constData() << std::endl; + if (urlString.startsWith("http://")) { + urlString.replace(0, 7, "zim://"); + } + std::cout << " + " << urlString.toUtf8().constData() << std::endl; + info.redirect(QUrl(urlString)); }