From 2b3efbfb2a88735d3fd943ab4dff5ed8219c8547 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 9 Sep 2022 15:56:36 +0200 Subject: [PATCH] Accept valid lsColJob reply XML content types Signed-off-by: Claudio Cambra --- src/libsync/discoveryphase.cpp | 16 +++++++++++----- src/libsync/networkjobs.cpp | 11 ++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 67b91ad872c79..1f45765642075 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -583,14 +583,20 @@ void DiscoverySingleDirectoryJob::lsJobFinishedWithoutErrorSlot() void DiscoverySingleDirectoryJob::lsJobFinishedWithErrorSlot(QNetworkReply *r) { - QString contentType = r->header(QNetworkRequest::ContentTypeHeader).toString(); - int httpCode = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - QString msg = r->errorString(); + const auto contentType = r->header(QNetworkRequest::ContentTypeHeader).toString(); + const auto invalidContentType = !contentType.contains("application/xml; charset=utf-8") && + !contentType.contains("application/xml; charset=\"utf-8\"") && + !contentType.contains("text/xml; charset=utf-8") && + !contentType.contains("text/xml; charset=\"utf-8\""); + const auto httpCode = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + auto msg = r->errorString(); + qCWarning(lcDiscovery) << "LSCOL job error" << r->errorString() << httpCode << r->error(); - if (r->error() == QNetworkReply::NoError - && !contentType.contains("application/xml; charset=utf-8")) { + + if (r->error() == QNetworkReply::NoError && invalidContentType) { msg = tr("Server error: PROPFIND reply is not XML formatted!"); } + emit finished(HttpError{ httpCode, msg }); deleteLater(); } diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index 335dd1eb548c2..91970b5ced62b 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -395,9 +395,14 @@ bool LsColJob::finished() qCInfo(lcLsColJob) << "LSCOL of" << reply()->request().url() << "FINISHED WITH STATUS" << replyStatusString(); - QString contentType = reply()->header(QNetworkRequest::ContentTypeHeader).toString(); - int httpCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (httpCode == 207 && contentType.contains("application/xml; charset=utf-8")) { + const auto contentType = reply()->header(QNetworkRequest::ContentTypeHeader).toString(); + const auto httpCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + const auto validContentType = contentType.contains("application/xml; charset=utf-8") || + contentType.contains("application/xml; charset=\"utf-8\"") || + contentType.contains("text/xml; charset=utf-8") || + contentType.contains("text/xml; charset=\"utf-8\""); + + if (httpCode == 207 && validContentType) { LsColXMLParser parser; connect(&parser, &LsColXMLParser::directoryListingSubfolders, this, &LsColJob::directoryListingSubfolders);