From 34976a42c68446adbe33cd713ce3bf18f9e78a50 Mon Sep 17 00:00:00 2001 From: Arno Rehn Date: Fri, 23 Jun 2023 11:00:59 +0200 Subject: [PATCH] Client: Work around missing Authorization header QNetworkAccessManager only sends the Authorization header after the server replies with status code 401. Not all servers do this (in particular, Maia's own XMLRPC server does not do this). Work around the issue by manually building the required Authorization header from the URL's user info. --- maia/maiaXmlRpcClient.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/maia/maiaXmlRpcClient.cpp b/maia/maiaXmlRpcClient.cpp index a0ad281..ab03b8c 100644 --- a/maia/maiaXmlRpcClient.cpp +++ b/maia/maiaXmlRpcClient.cpp @@ -63,6 +63,15 @@ void MaiaXmlRpcClient::setUrl(QUrl url) { return; request.setUrl(url); + + const QString userInfo = request.url().userInfo(QUrl::FullyEncoded); + QByteArray auth; + if (!userInfo.isEmpty()) { + // Work around QTBUG-114119 + // "QNetworkAccessManager only tries to authenticate if the server responds with 401" + auth = "Basic " + userInfo.toUtf8().toBase64(); + } + request.setRawHeader("Authorization", auth); } void MaiaXmlRpcClient::setUserAgent(QString userAgent) {