Skip to content

Commit 3a37ec5

Browse files
committed
test: isTextBody
1 parent 9750a0b commit 3a37ec5

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/libsync/httplogger.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ Q_LOGGING_CATEGORY(lcNetworkHttp, "sync.httplogger", QtWarningMsg)
3434

3535
const qint64 PeekSize = 1024 * 1024;
3636

37-
bool isTextBody(const QString &s)
38-
{
39-
static const QRegularExpression regexp(QStringLiteral("^(text/.*?|(application/(xml|.*?json|x-www-form-urlencoded)(;|$)))"));
40-
return regexp.match(s).hasMatch();
41-
}
42-
4337
struct HttpContext
4438
{
4539
HttpContext(const QNetworkRequest &request)
@@ -106,7 +100,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO
106100
QJsonObject body = {{QStringLiteral("length"), contentLength}};
107101
if (contentLength > 0) {
108102
const QString contentType = header.value(QStringLiteral("Content-Type")).toString();
109-
if (isTextBody(contentType)) {
103+
if (OCC::HttpLogger::isTextBody(contentType)) {
110104
if (!device->isOpen()) {
111105
Q_ASSERT(dynamic_cast<QBuffer *>(device));
112106
// should we close it again?
@@ -205,4 +199,9 @@ QByteArray HttpLogger::requestVerb(QNetworkAccessManager::Operation operation, c
205199
Q_UNREACHABLE();
206200
}
207201

202+
bool HttpLogger::isTextBody(const QString &s)
203+
{
204+
static const QRegularExpression regexp(QStringLiteral("^(text/.*?|(application/(xml|.*?json|x-www-form-urlencoded)(;|$)))"));
205+
return regexp.match(s).hasMatch();
206+
}
208207
}

src/libsync/httplogger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ namespace HttpLogger {
3030
{
3131
return requestVerb(reply.operation(), reply.request());
3232
}
33+
34+
bool OWNCLOUDSYNC_EXPORT isTextBody(const QString &s);
3335
}
3436
}

test/testutility.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "common/filesystembase.h"
1414
#include "common/utility.h"
15+
#include "libsync/httplogger.h"
1516

1617
using namespace std::chrono_literals;
1718

@@ -322,6 +323,12 @@ private Q_SLOTS:
322323
QVERIFY(Tags::remove(fn, testKey));
323324
QVERIFY(!Tags::get(fn, testKey).has_value());
324325
}
326+
327+
void testHttpContentTypeIsText()
328+
{
329+
QVERIFY(OCC::HttpLogger::isTextBody(QStringLiteral("application/json; charset=utf-8")));
330+
QVERIFY(OCC::HttpLogger::isTextBody(QStringLiteral("application/json")));
331+
}
325332
};
326333

327334
QTEST_GUILESS_MAIN(TestUtility)

0 commit comments

Comments
 (0)