Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: http header keys are case in-sensitive #11993

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.8 NAMES Qt6 COMPONENTS Core REQUIRED)

find_package(Qt6 COMPONENTS Core Concurrent Network Widgets Xml Quick QuickWidgets QuickControls2 REQUIRED)
find_package(Qt6LinguistTools REQUIRED)
Expand Down
22 changes: 9 additions & 13 deletions src/libsync/httplogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,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<QNetworkReply *>(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]"));
}
}

Expand Down Expand Up @@ -105,10 +105,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<QBuffer *>(device));
Expand All @@ -117,8 +114,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;
Expand Down Expand Up @@ -166,7 +162,7 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati
for (const auto &key : request.rawHeaderList()) {
header[QString::fromUtf8(key)] = QString::fromUtf8(request.rawHeader(key));
}
logHttp(requestVerb(operation, request), ctx, std::move(header), device, cached);
logHttp(requestVerb(operation, request), request.headers(), ctx, std::move(header), device, cached);
};
QObject::connect(reply, &QNetworkReply::requestSent, reply, logSend, Qt::DirectConnection);

Expand All @@ -182,7 +178,7 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati
for (const auto &[key, value] : reply->rawHeaderPairs()) {
header[QString::fromUtf8(key)] = QString::fromUtf8(value);
}
logHttp(requestVerb(*reply), ctx.get(), std::move(header), reply);
logHttp(requestVerb(*reply), reply->headers(), ctx.get(), std::move(header), reply);
},
Qt::DirectConnection);
}
Expand Down