@@ -64,17 +64,17 @@ struct HttpContext
64
64
bool send = false ;
65
65
};
66
66
67
- void logHttp (const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIODevice *device, bool cached = false )
67
+ void logHttp (const QByteArray &verb, const QHttpHeaders &headers, HttpContext *ctx, QJsonObject &&header, QIODevice *device, bool cached = false )
68
68
{
69
69
static const bool redact = !qEnvironmentVariableIsSet (" OWNCLOUD_HTTPLOGGER_NO_REDACT" );
70
70
const auto reply = qobject_cast<QNetworkReply *>(device);
71
71
const auto contentLength = device ? device->size () : 0 ;
72
72
73
73
if (redact) {
74
- const QString authKey = QStringLiteral ( " Authorization" );
75
- const QString auth = header .value (authKey). toString ( );
76
- if (!auth. isEmpty ()) {
77
- header. insert (authKey, auth.startsWith (QStringLiteral (" Bearer " )) ? QStringLiteral (" Bearer [redacted]" ) : QStringLiteral (" Basic [redacted]" ));
74
+ if (headers. contains (QHttpHeaders::WellKnownHeader:: Authorization)) {
75
+ const auto auth = QString::fromUtf8 (headers .value (QHttpHeaders::WellKnownHeader::Authorization) );
76
+ header. insert ( QStringLiteral ( " Authorization " ),
77
+ auth.startsWith (QStringLiteral (" Bearer " )) ? QStringLiteral (" Bearer [redacted]" ) : QStringLiteral (" Basic [redacted]" ));
78
78
}
79
79
}
80
80
@@ -105,10 +105,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO
105
105
106
106
QJsonObject body = {{QStringLiteral (" length" ), contentLength}};
107
107
if (contentLength > 0 ) {
108
- QString contentType = header.value (QStringLiteral (" Content-Type" )).toString ();
109
- if (contentType.isEmpty ()) {
110
- contentType = header.value (QStringLiteral (" content-type" )).toString ();
111
- }
108
+ const auto contentType = QString::fromUtf8 (headers.value (QHttpHeaders::WellKnownHeader::ContentType));
112
109
if (isTextBody (contentType)) {
113
110
if (!device->isOpen ()) {
114
111
Q_ASSERT (dynamic_cast <QBuffer *>(device));
@@ -117,8 +114,7 @@ void logHttp(const QByteArray &verb, HttpContext *ctx, QJsonObject &&header, QIO
117
114
}
118
115
Q_ASSERT (device->pos () == 0 );
119
116
QString data = QString::fromUtf8 (device->peek (PeekSize));
120
- if (PeekSize < contentLength)
121
- {
117
+ if (PeekSize < contentLength) {
122
118
data += QStringLiteral (" ...(%1 bytes elided)" ).arg (QString::number (contentLength - PeekSize));
123
119
}
124
120
body[QStringLiteral (" data" )] = data;
@@ -166,7 +162,7 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati
166
162
for (const auto &key : request.rawHeaderList ()) {
167
163
header[QString::fromUtf8 (key)] = QString::fromUtf8 (request.rawHeader (key));
168
164
}
169
- logHttp (requestVerb (operation, request), ctx, std::move (header), device, cached);
165
+ logHttp (requestVerb (operation, request), request. headers (), ctx, std::move (header), device, cached);
170
166
};
171
167
QObject::connect (reply, &QNetworkReply::requestSent, reply, logSend, Qt::DirectConnection);
172
168
@@ -182,7 +178,7 @@ void HttpLogger::logRequest(QNetworkReply *reply, QNetworkAccessManager::Operati
182
178
for (const auto &[key, value] : reply->rawHeaderPairs ()) {
183
179
header[QString::fromUtf8 (key)] = QString::fromUtf8 (value);
184
180
}
185
- logHttp (requestVerb (*reply), ctx.get (), std::move (header), reply);
181
+ logHttp (requestVerb (*reply), reply-> headers (), ctx.get (), std::move (header), reply);
186
182
},
187
183
Qt::DirectConnection);
188
184
}
0 commit comments