From 67d9257b828a05fea8b635cd07a4c98ffef4398c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <1005065+DeepDiver1975@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:51:27 +0100 Subject: [PATCH] fix: http header keys are case in-sensitive --- .drone.star | 2 +- CMakeLists.txt | 2 +- src/libsync/httplogger.cpp | 35 ++++++++++++++++++++--------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.drone.star b/.drone.star index 27855ef271c..9afcb4f361d 100644 --- a/.drone.star +++ b/.drone.star @@ -23,7 +23,7 @@ OC_UBUNTU = "owncloud/ubuntu:20.04" # Todo: update or remove the following images # https://github.com/owncloud/client/issues/10070 OC_CI_CLIENT_FEDORA = "owncloudci/client:fedora-39-amd64" -OC_CI_SQUISH = "owncloudci/squish:fedora-39-7.2.1-qt66x-linux64" +OC_CI_SQUISH = "owncloudci/squish:fedora-39-8.0.0-qt67x-linux64" PLUGINS_GIT_ACTION = "plugins/git-action:1" PLUGINS_S3 = "plugins/s3:1.4.0" diff --git a/CMakeLists.txt b/CMakeLists.txt index a435ec0eb99..0ac9bd7cb33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ set(APPLE_SUPPRESS_X11_WARNING ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -find_package(QT 6.5 NAMES Qt6 COMPONENTS Core REQUIRED) +find_package(QT 6.7 NAMES Qt6 COMPONENTS Core REQUIRED) find_package(Qt6 COMPONENTS Core Concurrent Network Widgets Xml Quick QuickWidgets QuickControls2 REQUIRED) find_package(Qt6LinguistTools REQUIRED) diff --git a/src/libsync/httplogger.cpp b/src/libsync/httplogger.cpp index 059dc90c5a8..4144b382633 100644 --- a/src/libsync/httplogger.cpp +++ b/src/libsync/httplogger.cpp @@ -18,6 +18,7 @@ #include "common/utility.h" #include +#include #include #include #include @@ -64,17 +65,17 @@ struct HttpContext bool send = false; }; -void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIODevice *device, bool cached = false) +void logHttp(const QByteArray &verb, const QHttpHeaders &headers, HttpContext *ctx, QJsonObject &&header, QIODevice *device, bool cached = false) { static const bool redact = !qEnvironmentVariableIsSet("OWNCLOUD_HTTPLOGGER_NO_REDACT"); const auto reply = qobject_cast(device); const auto contentLength = device ? device->size() : 0; if (redact) { - const QString authKey = QStringLiteral("Authorization"); - const QString auth = header.value(authKey).toString(); - if (!auth.isEmpty()) { - header.insert(authKey, auth.startsWith(QStringLiteral("Bearer ")) ? QStringLiteral("Bearer [redacted]") : QStringLiteral("Basic [redacted]")); + if (headers.contains(QHttpHeaders::WellKnownHeader::Authorization)) { + const auto auth = QString::fromUtf8(headers.value(QHttpHeaders::WellKnownHeader::Authorization)); + header.insert(QStringLiteral("Authorization"), + auth.startsWith(QStringLiteral("Bearer ")) ? QStringLiteral("Bearer [redacted]") : QStringLiteral("Basic [redacted]")); } } @@ -105,10 +106,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO QJsonObject body = {{QStringLiteral("length"), contentLength}}; if (contentLength > 0) { - QString contentType = header.value(QStringLiteral("Content-Type")).toString(); - if (contentType.isEmpty()) { - contentType = header.value(QStringLiteral("content-type")).toString(); - } + const auto contentType = QString::fromUtf8(headers.value(QHttpHeaders::WellKnownHeader::ContentType)); if (isTextBody(contentType)) { if (!device->isOpen()) { Q_ASSERT(dynamic_cast(device)); @@ -117,8 +115,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO } Q_ASSERT(device->pos() == 0); QString data = QString::fromUtf8(device->peek(PeekSize)); - if (PeekSize < contentLength) - { + if (PeekSize < contentLength) { data += QStringLiteral("...(%1 bytes elided)").arg(QString::number(contentLength - PeekSize)); } body[QStringLiteral("data")] = data; @@ -163,10 +160,14 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati const auto request = reply->request(); QJsonObject header; + QHttpHeaders h = {}; for (const auto &key : request.rawHeaderList()) { - header[QString::fromUtf8(key)] = QString::fromUtf8(request.rawHeader(key)); + auto k = QString::fromUtf8(key); + auto v = QString::fromUtf8(request.rawHeader(key)); + header[k] = v; + h.append(k, v); } - logHttp(requestVerb(operation, request), ctx, std::move(header), device, cached); + logHttp(requestVerb(operation, request), h, ctx, std::move(header), device, cached); }; QObject::connect(reply, &QNetworkReply::requestSent, reply, logSend, Qt::DirectConnection); @@ -179,10 +180,14 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati logSend(true); } QJsonObject header; + QHttpHeaders h = {}; for (const auto &[key, value] : reply->rawHeaderPairs()) { - header[QString::fromUtf8(key)] = QString::fromUtf8(value); + auto k = QString::fromUtf8(key); + auto v = QString::fromUtf8(value); + header[k] = v; + h.append(k, v); } - logHttp(requestVerb(*reply), ctx.get(), std::move(header), reply); + logHttp(requestVerb(*reply), h, ctx.get(), std::move(header), reply); }, Qt::DirectConnection); }