Skip to content

Commit 67d9257

Browse files
committed
fix: http header keys are case in-sensitive
1 parent 83d7be7 commit 67d9257

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

.drone.star

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ OC_UBUNTU = "owncloud/ubuntu:20.04"
2323
# Todo: update or remove the following images
2424
# https://github.com/owncloud/client/issues/10070
2525
OC_CI_CLIENT_FEDORA = "owncloudci/client:fedora-39-amd64"
26-
OC_CI_SQUISH = "owncloudci/squish:fedora-39-7.2.1-qt66x-linux64"
26+
OC_CI_SQUISH = "owncloudci/squish:fedora-39-8.0.0-qt67x-linux64"
2727

2828
PLUGINS_GIT_ACTION = "plugins/git-action:1"
2929
PLUGINS_S3 = "plugins/s3:1.4.0"

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set(APPLE_SUPPRESS_X11_WARNING ON)
1818

1919
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2020

21-
find_package(QT 6.5 NAMES Qt6 COMPONENTS Core REQUIRED)
21+
find_package(QT 6.7 NAMES Qt6 COMPONENTS Core REQUIRED)
2222

2323
find_package(Qt6 COMPONENTS Core Concurrent Network Widgets Xml Quick QuickWidgets QuickControls2 REQUIRED)
2424
find_package(Qt6LinguistTools REQUIRED)

src/libsync/httplogger.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "common/utility.h"
1919

2020
#include <QBuffer>
21+
#include <QHttpHeaders>
2122
#include <QJsonArray>
2223
#include <QJsonDocument>
2324
#include <QJsonObject>
@@ -64,17 +65,17 @@ struct HttpContext
6465
bool send = false;
6566
};
6667

67-
void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIODevice *device, bool cached = false)
68+
void logHttp(const QByteArray &verb, const QHttpHeaders &headers, HttpContext *ctx, QJsonObject &&header, QIODevice *device, bool cached = false)
6869
{
6970
static const bool redact = !qEnvironmentVariableIsSet("OWNCLOUD_HTTPLOGGER_NO_REDACT");
7071
const auto reply = qobject_cast<QNetworkReply *>(device);
7172
const auto contentLength = device ? device->size() : 0;
7273

7374
if (redact) {
74-
const QString authKey = QStringLiteral("Authorization");
75-
const QString auth = header.value(authKey).toString();
76-
if (!auth.isEmpty()) {
77-
header.insert(authKey, auth.startsWith(QStringLiteral("Bearer ")) ? QStringLiteral("Bearer [redacted]") : QStringLiteral("Basic [redacted]"));
75+
if (headers.contains(QHttpHeaders::WellKnownHeader::Authorization)) {
76+
const auto auth = QString::fromUtf8(headers.value(QHttpHeaders::WellKnownHeader::Authorization));
77+
header.insert(QStringLiteral("Authorization"),
78+
auth.startsWith(QStringLiteral("Bearer ")) ? QStringLiteral("Bearer [redacted]") : QStringLiteral("Basic [redacted]"));
7879
}
7980
}
8081

@@ -105,10 +106,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO
105106

106107
QJsonObject body = {{QStringLiteral("length"), contentLength}};
107108
if (contentLength > 0) {
108-
QString contentType = header.value(QStringLiteral("Content-Type")).toString();
109-
if (contentType.isEmpty()) {
110-
contentType = header.value(QStringLiteral("content-type")).toString();
111-
}
109+
const auto contentType = QString::fromUtf8(headers.value(QHttpHeaders::WellKnownHeader::ContentType));
112110
if (isTextBody(contentType)) {
113111
if (!device->isOpen()) {
114112
Q_ASSERT(dynamic_cast<QBuffer *>(device));
@@ -117,8 +115,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO
117115
}
118116
Q_ASSERT(device->pos() == 0);
119117
QString data = QString::fromUtf8(device->peek(PeekSize));
120-
if (PeekSize < contentLength)
121-
{
118+
if (PeekSize < contentLength) {
122119
data += QStringLiteral("...(%1 bytes elided)").arg(QString::number(contentLength - PeekSize));
123120
}
124121
body[QStringLiteral("data")] = data;
@@ -163,10 +160,14 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati
163160

164161
const auto request = reply->request();
165162
QJsonObject header;
163+
QHttpHeaders h = {};
166164
for (const auto &key : request.rawHeaderList()) {
167-
header[QString::fromUtf8(key)] = QString::fromUtf8(request.rawHeader(key));
165+
auto k = QString::fromUtf8(key);
166+
auto v = QString::fromUtf8(request.rawHeader(key));
167+
header[k] = v;
168+
h.append(k, v);
168169
}
169-
logHttp(requestVerb(operation, request), ctx, std::move(header), device, cached);
170+
logHttp(requestVerb(operation, request), h, ctx, std::move(header), device, cached);
170171
};
171172
QObject::connect(reply, &QNetworkReply::requestSent, reply, logSend, Qt::DirectConnection);
172173

@@ -179,10 +180,14 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati
179180
logSend(true);
180181
}
181182
QJsonObject header;
183+
QHttpHeaders h = {};
182184
for (const auto &[key, value] : reply->rawHeaderPairs()) {
183-
header[QString::fromUtf8(key)] = QString::fromUtf8(value);
185+
auto k = QString::fromUtf8(key);
186+
auto v = QString::fromUtf8(value);
187+
header[k] = v;
188+
h.append(k, v);
184189
}
185-
logHttp(requestVerb(*reply), ctx.get(), std::move(header), reply);
190+
logHttp(requestVerb(*reply), h, ctx.get(), std::move(header), reply);
186191
},
187192
Qt::DirectConnection);
188193
}

0 commit comments

Comments
 (0)