From bb39550f25a28ca4f28f28c74600fa4b35065ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <169163068+ThomasMuellerKiteworks@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:26:22 +0100 Subject: [PATCH] test: isTextBody --- src/libsync/httplogger.cpp | 13 ++++++------- src/libsync/httplogger.h | 2 ++ test/testutility.cpp | 7 +++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libsync/httplogger.cpp b/src/libsync/httplogger.cpp index 7f39883ee77..bfbacbb714c 100644 --- a/src/libsync/httplogger.cpp +++ b/src/libsync/httplogger.cpp @@ -33,12 +33,6 @@ Q_LOGGING_CATEGORY(lcNetworkHttp, "sync.httplogger", QtWarningMsg) const qint64 PeekSize = 1024 * 1024; -bool isTextBody(const QString &s) -{ - static const QRegularExpression regexp(QStringLiteral("^(text/.*?|(application/(xml|.*?json|x-www-form-urlencoded)(;|$)))")); - return regexp.match(s).hasMatch(); -} - struct HttpContext { HttpContext(const QNetworkRequest &request) @@ -108,7 +102,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO if (contentType.isEmpty()) { contentType = header.value(QStringLiteral("content-type")).toString(); } - if (isTextBody(contentType)) { + if (OCC::HttpLogger::isTextBody(contentType)) { if (!device->isOpen()) { // should we close it again? device->open(QIODevice::ReadOnly); @@ -212,4 +206,9 @@ QByteArray HttpLogger::requestVerb(QNetworkAccessManager::Operation operation, c Q_UNREACHABLE(); } +bool HttpLogger::isTextBody(const QString &s) +{ + static const QRegularExpression regexp(QStringLiteral("^(text/.*?|(application/(xml|.*?json|x-www-form-urlencoded)(;|$)))")); + return regexp.match(s).hasMatch(); +} } diff --git a/src/libsync/httplogger.h b/src/libsync/httplogger.h index 2dde6c11703..5f010835fb1 100644 --- a/src/libsync/httplogger.h +++ b/src/libsync/httplogger.h @@ -30,5 +30,7 @@ namespace HttpLogger { { return requestVerb(reply.operation(), reply.request()); } + + bool OWNCLOUDSYNC_EXPORT isTextBody(const QString &s); } } diff --git a/test/testutility.cpp b/test/testutility.cpp index 7fdfe5411ff..e12a8af40e5 100644 --- a/test/testutility.cpp +++ b/test/testutility.cpp @@ -15,6 +15,7 @@ #ifdef Q_OS_WIN #include "common/utility_win.h" #endif +#include "libsync/httplogger.h" using namespace std::chrono_literals; @@ -346,6 +347,12 @@ private Q_SLOTS: QCOMPARE(out.QuadPart, 137930652000000000); } #endif + + void testHttpContentTypeIsText() + { + QVERIFY(OCC::HttpLogger::isTextBody(QStringLiteral("application/json; charset=utf-8"))); + QVERIFY(OCC::HttpLogger::isTextBody(QStringLiteral("application/json"))); + } }; QTEST_GUILESS_MAIN(TestUtility)