Migrate old code from WebKit to WebEngine (QT6.5.2)
-
Hi guys,
Newbie here. I need some help to migrate this piece of WebKit code:
mutateURL(const QUrl &oldURL) { QByteArray ba; ba.append(oldURL.toString().toStdString().c_str()); QString newURL; newURL.append("http://192.168.1.21/check/"); newURL.append(ba); return QUrl::fromUserInput(newURL); } createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData) { QUrl url= mutateURL(request.url()); QNetworkRequest newReq = request; newReq.setUrl(url); QNetworkReply* mirroredRep = QNetworkAccessManager::createRequest(op, newReq, outgoingData); [...]
What this code does is pretty simple: it intercepts all HTTP requests, create a new destination URL (by prepending "http://192.168.1.21/check/") to it and send the new request.
As you can see, there's no "HTTP redirect involved". I would like to mimic this logic using WebEngine (QT6.5.2).
Help appreciated.
Many thanks -
Hi and welcome to devnet,
From a quick look at the documentation, it seems that QWebEngineUrlRequestInterceptor is what you are looking for.
On an unrelated note, why are you doing all these conversions through QByteArray since you want to concatenate two strings ?
-
Hi @SGaist
Thanks.
QWebEngineUrlRequestInterceptor is limited and only allows you to modify the HTTP request headers and/or perform an HTTP REDIRECT which I'd like to avoid here.
The old code doesn't perform any REDIRECT.
QByteArray since you want to concatenate two strings
Indeed. As stated in the title, this is an old code :-)