Skip to content
Open
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
13 changes: 6 additions & 7 deletions src/libsync/httplogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions src/libsync/httplogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ namespace HttpLogger {
{
return requestVerb(reply.operation(), reply.request());
}

bool OWNCLOUDSYNC_EXPORT isTextBody(const QString &s);
}
}
7 changes: 7 additions & 0 deletions test/testutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifdef Q_OS_WIN
#include "common/utility_win.h"
#endif
#include "libsync/httplogger.h"

using namespace std::chrono_literals;

Expand Down Expand Up @@ -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)
Expand Down
Loading