Add QDebug support to QHttpPart
As part of QTBUG-114647 we are planning to introduce a deduction mechanism that could deduce the contentType header and the contentDisposition headers based on the arguments (and the MIME database). In case of non-trivial types this deduction may give the wrong result and without QDebug support it might be a bit tedious to check. The debug output displays some information about the body device if one is attached, otherwise it displays the size of the body. Task-number: QTBUG-114647 Change-Id: Ia693b078ff5b9f8ea57fbf3c385edaec47886ff1 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
b64932ba82
commit
3377b74df9
@ -511,6 +511,48 @@ qint64 QHttpMultiPartIODevice::writeData(const char *data, qint64 maxSize)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
||||
/*!
|
||||
\fn QDebug QHttpPart::operator<<(QDebug debug, const QHttpPart &part)
|
||||
|
||||
Writes the \a part into the \a debug object for debugging purposes.
|
||||
Unless a device is set, the size of the body is shown.
|
||||
|
||||
\sa {Debugging Techniques}
|
||||
\since 6.8
|
||||
*/
|
||||
|
||||
QDebug operator<<(QDebug debug, const QHttpPart &part)
|
||||
{
|
||||
const QDebugStateSaver saver(debug);
|
||||
debug.resetFormat().nospace().noquote();
|
||||
|
||||
debug << "QHttpPart(headers = ["
|
||||
<< part.d->cookedHeaders
|
||||
<< "], raw headers = ["
|
||||
<< part.d->rawHeaders
|
||||
<< "],";
|
||||
|
||||
if (part.d->bodyDevice) {
|
||||
debug << " bodydevice = ["
|
||||
<< part.d->bodyDevice
|
||||
<< ", is open: "
|
||||
<< part.d->bodyDevice->isOpen()
|
||||
<< "]";
|
||||
} else {
|
||||
debug << " size of body = "
|
||||
<< part.d->body.size()
|
||||
<< " bytes";
|
||||
}
|
||||
|
||||
debug << ")";
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
#endif // QT_NO_DEBUG_STREAM
|
||||
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -19,6 +19,7 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
class QHttpPartPrivate;
|
||||
class QHttpMultiPart;
|
||||
class QDebug;
|
||||
|
||||
class Q_NETWORK_EXPORT QHttpPart
|
||||
{
|
||||
@ -45,6 +46,9 @@ private:
|
||||
QSharedDataPointer<QHttpPartPrivate> d;
|
||||
|
||||
friend class QHttpMultiPartIODevice;
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
friend Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QHttpPart &httpPart);
|
||||
#endif
|
||||
};
|
||||
|
||||
Q_DECLARE_SHARED(QHttpPart)
|
||||
|
@ -560,6 +560,9 @@ private Q_SLOTS:
|
||||
void notFoundWithCompression_data();
|
||||
void notFoundWithCompression();
|
||||
|
||||
void qhttpPartDebug_data();
|
||||
void qhttpPartDebug();
|
||||
|
||||
void qtbug68821proxyError_data();
|
||||
void qtbug68821proxyError();
|
||||
|
||||
@ -10479,6 +10482,59 @@ void tst_QNetworkReply::notFoundWithCompression()
|
||||
QCOMPARE(reply->readAll(), expected);
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::qhttpPartDebug_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("header_data");
|
||||
QTest::addColumn<QByteArray>("raw_header_data");
|
||||
QTest::addColumn<QList<QByteArray>>("expected_header_values");
|
||||
QTest::addColumn<bool>("overwrite");
|
||||
|
||||
QTest::newRow("header-data-set") << "form-data; name=\"prompt\""_ba << ""_ba
|
||||
<< (QList<QByteArray>() << "form-data; name=\"prompt\""_ba) << false;
|
||||
QTest::newRow("raw-header-data-set") << ""_ba << "thisismykeyherebutnotreally"_ba
|
||||
<< (QList<QByteArray>() << "thisismykeyherebutnotreally"_ba) << false;
|
||||
QTest::newRow("both-set") << "form-data; name=\"prompt\""_ba
|
||||
<< "thisismykeyherebutnotreally"_ba
|
||||
<< (QList<QByteArray>()
|
||||
<< "form-data; name=\"prompt\""_ba
|
||||
<< "thisismykeyherebutnotreally"_ba) << false;
|
||||
QTest::newRow("overwrite") << "form-data; name=\"prompt\""_ba
|
||||
<< "thisismykeyherebutnotreally"_ba
|
||||
<< (QList<QByteArray>()
|
||||
<< "thisismykeyherebutnotreally"_ba
|
||||
<< "thisismykeyherebutnotreally"_ba) << true;
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::qhttpPartDebug()
|
||||
{
|
||||
QFETCH(const QByteArray, header_data);
|
||||
QFETCH(const QByteArray, raw_header_data);
|
||||
QFETCH(const QList<QByteArray>, expected_header_values);
|
||||
QFETCH(bool, overwrite);
|
||||
|
||||
QHttpPart httpPart;
|
||||
|
||||
if (!header_data.isEmpty())
|
||||
httpPart.setHeader(QNetworkRequest::ContentDispositionHeader, header_data);
|
||||
|
||||
if (!raw_header_data.isEmpty())
|
||||
httpPart.setRawHeader("Authorization", raw_header_data);
|
||||
|
||||
if (overwrite)
|
||||
httpPart.setRawHeader("Content-Disposition", raw_header_data);
|
||||
|
||||
QByteArray msg;
|
||||
{
|
||||
QBuffer buf(&msg);
|
||||
QVERIFY(buf.open(QIODevice::WriteOnly));
|
||||
QDebug debug(&buf);
|
||||
debug << httpPart;
|
||||
}
|
||||
|
||||
for (const auto &value : expected_header_values)
|
||||
QVERIFY2(msg.contains(value), "Missing header value: " + value);
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::qtbug68821proxyError_data()
|
||||
{
|
||||
QTest::addColumn<QString>("proxyHost");
|
||||
|
Loading…
x
Reference in New Issue
Block a user