7#include <QtNetwork/private/qnetworkreply_p.h>
8#include <QtNetwork/private/qrestaccessmanager_p.h>
10#include <QtCore/qbytearrayview.h>
11#include <QtCore/qjsondocument.h>
12#include <QtCore/qlatin1stringmatcher.h>
13#include <QtCore/qlatin1stringview.h>
14#include <QtCore/qloggingcategory.h>
15#include <QtCore/qstringconverter.h>
17#include <QtCore/qxpfunctional.h>
53 qCWarning(lcQrest,
"QRestReply: QNetworkReply is nullptr");
118 qCWarning(lcQrest,
"readJson() called on an unfinished reply, ignoring");
128 if (parseError.
error)
182 qCWarning(lcQrest,
"readText(): Charset \"%s\" is not supported", charset.
constData());
188 qCWarning(lcQrest,
"readText(): Decoding error occurred");
231 return status >= 200 && status < 300;
268 return wrapped->
error();
289#ifndef QT_NO_DEBUG_STREAM
308 Q_UNREACHABLE_RETURN({});
321 debug.resetFormat().nospace();
322 if (!
reply.networkReply()) {
323 debug <<
"QRestReply(no network reply)";
326 debug <<
"QRestReply(isSuccess = " <<
reply.isSuccess()
327 <<
", httpStatus = " <<
reply.httpStatus()
328 <<
", isHttpStatusSuccess = " <<
reply.isHttpStatusSuccess()
329 <<
", hasError = " <<
reply.hasError()
334 <<
", url " <<
reply.networkReply()->
url()
336 <<
", reply headers = " <<
reply.networkReply()->
headers()
348 constexpr auto is_OWS_char = [](
auto ch) {
return ch ==
' ' ||
ch ==
'\t'; };
351 while (
i <
data.size() && is_OWS_char(
data[
i]))
366 constexpr explicit operator bool()
const noexcept {
return !quotedString.
isEmpty(); }
369 if (!
data.startsWith(
'"'))
373 while (
i <
data.size()) {
381 if (
i ==
data.size())
415 return (
ch >=
'a' &&
ch <=
'z')
416 || (
ch >=
'0' &&
ch <=
'9')
417 || (
ch >=
'A' &&
ch <=
'Z');
425 constexpr explicit operator bool()
const noexcept {
return !comment.
isEmpty(); }
428 const auto invalid =
R{{},
data};
433 if (!
data.startsWith(
'('))
438 while (
i <
data.size()) {
448 if (
i ==
data.size())
473 constexpr explicit operator bool()
const noexcept {
return !
token.isEmpty(); }
487 constexpr explicit operator bool()
const noexcept {
return !
name.
isEmpty(); }
490 const auto invalid =
R{{}, {},
data};
503 if (!
data.startsWith(
'='))
534 constexpr explicit operator bool()
const noexcept {
return !
type.
isEmpty(); }
546 if (!
data.startsWith(
'/'))
561 while (
data.startsWith(
';')) {
569 if (
r.charset.empty() && !
param.value.startsWith(
'"'))
570 r.charset.assign(
param.value.begin(),
param.value.end());
600 if (
r && !
r.charset.empty())
QByteArray toByteArray() const
constexpr bool isEmpty() const noexcept
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
\inmodule QtCore\reentrant
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
constexpr bool isEmpty() const noexcept
constexpr QLatin1StringView sliced(qsizetype pos) const
Operation
Indicates the operation this reply is processing.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
QNetworkAccessManager::Operation operation() const
Returns the operation that was posted for this reply.
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
QHttpHeaders headers() const
NetworkError error() const
Returns the error that was found during the processing of this request.
NetworkError
Indicates all possible error conditions found during the processing of the request.
QUrl url() const
Returns the URL of the content downloaded or uploaded.
@ HttpStatusCodeAttribute
std::optional< QStringDecoder > decoder
static QByteArray contentCharset(const QNetworkReply *reply)
QRestReply is a convenience wrapper for QNetworkReply.
Q_NETWORK_EXPORT std::optional< QJsonDocument > readJson(QJsonParseError *error=nullptr)
Returns the received data as a QJsonDocument.
Q_NETWORK_EXPORT int httpStatus() const
Returns the HTTP status received in the server response.
Q_NETWORK_EXPORT bool isHttpStatusSuccess() const
Returns whether the HTTP status is between 200..299.
Q_NETWORK_EXPORT QString errorString() const
Returns a human-readable description of the last network error.
Q_NETWORK_EXPORT bool hasError() const
Returns whether an error has occurred.
Q_NETWORK_EXPORT QRestReply(QNetworkReply *reply)
Creates a QRestReply and initializes the wrapped QNetworkReply to reply.
Q_NETWORK_EXPORT QByteArray readBody()
Returns the received data as a QByteArray.
Q_NETWORK_EXPORT QNetworkReply * networkReply() const
Returns a pointer to the underlying QNetworkReply wrapped by this object.
Q_NETWORK_EXPORT QNetworkReply::NetworkError error() const
Returns the last error, if any.
Q_NETWORK_EXPORT QString readText()
Returns the received data as a QString.
Q_NETWORK_EXPORT ~QRestReply()
Destroys this QRestReply object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCWarning(category,...)
GLenum GLuint GLint level
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum const GLint * param
static constexpr auto parse_quoted_string(QByteArrayView data, qxp::function_ref< void(char) const > yield)
QDebug operator<<(QDebug debug, const QRestReply &reply)
static constexpr void eat_OWS(QByteArrayView &data) noexcept
static constexpr auto parse_token(QByteArrayView data) noexcept
static auto parse_content_type(QByteArrayView data)
static constexpr auto parse_parameter(QByteArrayView data, qxp::function_ref< void(char) const > yield)
static QLatin1StringView operationName(QNetworkAccessManager::Operation operation)
static constexpr auto parse_comment(QByteArrayView data) noexcept
static constexpr bool is_tchar(char ch) noexcept
static constexpr auto parse_OWS(QByteArrayView data) noexcept
static constexpr void eat_CWS(QByteArrayView &data) noexcept
\inmodule QtCore\reentrant