summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2023-08-10 10:36:17 +0300
committerJuha Vuolle <juha.vuolle@qt.io>2023-12-08 15:53:35 +0200
commit0f34316fb7e4d1e542b5f72d43f5123d6cb5f780 (patch)
tree86bdc8fdff419fb79b1e576df97497b9a33801ed /src/network/access
parent6420e8b89553af2e3c1b61a8d81fb55afb0930e2 (diff)
Add QDebug support for QRestReply
Task-number: QTBUG-114705 Change-Id: I6c355d683389b773082c5966434d733bf5aec506 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/access')
-rw-r--r--src/network/access/qrestreply.cpp54
-rw-r--r--src/network/access/qrestreply.h4
2 files changed, 58 insertions, 0 deletions
diff --git a/src/network/access/qrestreply.cpp b/src/network/access/qrestreply.cpp
index 82be72d2d4..c4f435d68e 100644
--- a/src/network/access/qrestreply.cpp
+++ b/src/network/access/qrestreply.cpp
@@ -367,6 +367,60 @@ QRestReplyPrivate::QRestReplyPrivate()
QRestReplyPrivate::~QRestReplyPrivate()
= default;
+#ifndef QT_NO_DEBUG_STREAM
+static QLatin1StringView operationName(QNetworkAccessManager::Operation operation)
+{
+ switch (operation) {
+ case QNetworkAccessManager::Operation::GetOperation:
+ return "GET"_L1;
+ case QNetworkAccessManager::Operation::HeadOperation:
+ return "HEAD"_L1;
+ case QNetworkAccessManager::Operation::PostOperation:
+ return "POST"_L1;
+ case QNetworkAccessManager::Operation::PutOperation:
+ return "PUT"_L1;
+ case QNetworkAccessManager::Operation::DeleteOperation:
+ return "DELETE"_L1;
+ case QNetworkAccessManager::Operation::CustomOperation:
+ return "CUSTOM"_L1;
+ case QNetworkAccessManager::Operation::UnknownOperation:
+ return "UNKNOWN"_L1;
+ }
+ Q_UNREACHABLE_RETURN({});
+}
+
+/*!
+ \fn QDebug QRestReply::operator<<(QDebug debug, const QRestReply *reply)
+
+ Writes the \a reply into the \a debug object for debugging purposes.
+
+ \sa {Debugging Techniques}
+*/
+QDebug operator<<(QDebug debug, const QRestReply *reply)
+{
+ const QDebugStateSaver saver(debug);
+ debug.resetFormat().nospace();
+ if (!reply) {
+ debug << "QRestReply(nullptr)";
+ return debug;
+ }
+
+ debug << "QRestReply(isSuccess = " << reply->isSuccess()
+ << ", httpStatus = " << reply->httpStatus()
+ << ", isHttpStatusSuccess = " << reply->isHttpStatusSuccess()
+ << ", hasError = " << reply->hasError()
+ << ", errorString = " << reply->errorString()
+ << ", error = " << reply->error()
+ << ", isFinished = " << reply->isFinished()
+ << ", bytesAvailable = " << reply->bytesAvailable()
+ << ", url " << reply->networkReply()->url()
+ << ", operation = " << operationName(reply->networkReply()->operation())
+ << ", reply headers = " << reply->networkReply()->rawHeaderPairs()
+ << ")";
+ return debug;
+}
+#endif // QT_NO_DEBUG_STREAM
+
QByteArray QRestReplyPrivate::contentCharset() const
{
// Content-type consists of mimetype and optional parameters, of which one may be 'charset'
diff --git a/src/network/access/qrestreply.h b/src/network/access/qrestreply.h
index eb547f9b5d..e022a7b853 100644
--- a/src/network/access/qrestreply.h
+++ b/src/network/access/qrestreply.h
@@ -8,6 +8,7 @@
QT_BEGIN_NAMESPACE
+class QDebug;
class QRestReplyPrivate;
class Q_NETWORK_EXPORT QRestReply : public QObject
{
@@ -49,6 +50,9 @@ Q_SIGNALS:
private:
friend class QRestAccessManagerPrivate;
+#ifndef QT_NO_DEBUG_STREAM
+ friend Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QRestReply *reply);
+#endif
explicit QRestReply(QNetworkReply *reply, QObject *parent = nullptr);
Q_DECLARE_PRIVATE(QRestReply)
Q_DISABLE_COPY_MOVE(QRestReply)