@@ -68,7 +68,6 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO
68
68
{
69
69
static const bool redact = !qEnvironmentVariableIsSet (" OWNCLOUD_HTTPLOGGER_NO_REDACT" );
70
70
const auto reply = qobject_cast<QNetworkReply *>(device);
71
- const auto contentLength = device ? device->size () : 0 ;
72
71
73
72
if (redact) {
74
73
const QString authKey = QStringLiteral (" Authorization" );
@@ -103,7 +102,8 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO
103
102
info.insert (QStringLiteral (" cached" ), cached);
104
103
}
105
104
106
- QJsonObject body = {{QStringLiteral (" length" ), contentLength}};
105
+ const auto contentLength = device ? device->size () : 0 ;
106
+ QJsonObject body = {{QStringLiteral (" length" ), device ? QString::number (contentLength) : QStringLiteral (" null" )}};
107
107
if (contentLength > 0 ) {
108
108
QString contentType = header.value (QStringLiteral (" Content-Type" )).toString ();
109
109
if (contentType.isEmpty ()) {
@@ -146,19 +146,24 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati
146
146
147
147
auto ctx = std::make_unique<HttpContext>(reply->request ());
148
148
149
+ const auto logError = [reply, operation, id = ctx->id ]() {
150
+ auto url = reply->request ().url ();
151
+ qCInfo (lcNetworkHttp).noquote ().nospace () << " An error occurred for " << url.toDisplayString () << " : " << reply->errorString () << " (" << reply->error ()
152
+ << " , " << operation << " ), request-id: " << id;
153
+ };
154
+
149
155
// device should still exist, lets still use a qpointer to ensure we have valid data
150
- const auto logSend = [ctx = ctx.get (), operation, reply, device = QPointer<QIODevice>(device), deviceRaw = device](bool cached = false ) {
156
+ const auto logSend = [ctx = ctx.get (), operation, reply, device = QPointer<QIODevice>(device), deviceRaw = device, logError ](bool cached = false ) {
151
157
Q_ASSERT (!deviceRaw || device);
152
158
if (!ctx->send ) {
153
159
ctx->send = true ;
154
160
ctx->timer .reset ();
155
- } else {
161
+ } else if (ctx-> lastUrl != reply-> url ()) {
156
162
// this is a redirect
157
- if (ctx->lastUrl != reply->url ()) {
158
- ctx->addRedirect (reply->url ());
159
- } else {
160
- Q_UNREACHABLE ();
161
- }
163
+ ctx->addRedirect (reply->url ());
164
+ } else {
165
+ // Probably an error (time-out?).
166
+ logError ();
162
167
}
163
168
164
169
const auto request = reply->request ();
@@ -169,6 +174,7 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati
169
174
logHttp (requestVerb (operation, request), ctx, std::move (header), device, cached);
170
175
};
171
176
QObject::connect (reply, &QNetworkReply::requestSent, reply, logSend, Qt::DirectConnection);
177
+ QObject::connect (reply, &QNetworkReply::errorOccurred, reply, logError, Qt::DirectConnection);
172
178
173
179
174
180
QObject::connect (
0 commit comments