diff --git a/src/libsync/httplogger.cpp b/src/libsync/httplogger.cpp index d86fd83a76c..fc10616a611 100644 --- a/src/libsync/httplogger.cpp +++ b/src/libsync/httplogger.cpp @@ -34,12 +34,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) @@ -106,7 +100,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO QJsonObject body = {{QStringLiteral("length"), contentLength}}; if (contentLength > 0) { const QString contentType = header.value(QStringLiteral("Content-Type")).toString(); - if (isTextBody(contentType)) { + if (OCC::HttpLogger::isTextBody(contentType)) { if (!device->isOpen()) { Q_ASSERT(dynamic_cast(device)); // should we close it again? @@ -205,4 +199,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 af2dacaf4be..4ec883a3408 100644 --- a/test/testutility.cpp +++ b/test/testutility.cpp @@ -12,6 +12,7 @@ #include "common/filesystembase.h" #include "common/utility.h" +#include "libsync/httplogger.h" using namespace std::chrono_literals; @@ -322,6 +323,12 @@ private Q_SLOTS: QVERIFY(Tags::remove(fn, testKey)); QVERIFY(!Tags::get(fn, testKey).has_value()); } + + void testHttpContentTypeIsText() + { + QVERIFY(OCC::HttpLogger::isTextBody(QStringLiteral("application/json; charset=utf-8"))); + QVERIFY(OCC::HttpLogger::isTextBody(QStringLiteral("application/json"))); + } }; QTEST_GUILESS_MAIN(TestUtility)