summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorMate Barany <mate.barany@qt.io>2023-11-14 15:10:38 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-05-03 15:16:14 +0000
commit3377b74df903cdaa99b5d1c83680e13b78674a08 (patch)
treedcc37c7eb414fb9df05164c363f65505177358a4 /src/network
parentb64932ba82ebdb4d03815263570b7a9d2ea1dc92 (diff)
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>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhttpmultipart.cpp42
-rw-r--r--src/network/access/qhttpmultipart.h4
2 files changed, 46 insertions, 0 deletions
diff --git a/src/network/access/qhttpmultipart.cpp b/src/network/access/qhttpmultipart.cpp
index 6d81f1b957..2b5f1163c8 100644
--- a/src/network/access/qhttpmultipart.cpp
+++ b/src/network/access/qhttpmultipart.cpp
@@ -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
diff --git a/src/network/access/qhttpmultipart.h b/src/network/access/qhttpmultipart.h
index 26e5fafdf2..9732bbd99d 100644
--- a/src/network/access/qhttpmultipart.h
+++ b/src/network/access/qhttpmultipart.h
@@ -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)