7#include <QtNetwork/private/qnetworkreply_p.h>
9#include <QtCore/qbytearrayview.h>
10#include <QtCore/qjsondocument.h>
11#include <QtCore/qlatin1stringmatcher.h>
12#include <QtCore/qlatin1stringview.h>
13#include <QtCore/qloggingcategory.h>
14#include <QtCore/qstringconverter.h>
16#include <QtCore/qxpfunctional.h>
55 qCWarning(lcQrest,
"QRestReply: QNetworkReply is nullptr");
120 qCWarning(lcQrest,
"readJson() called on an unfinished reply, ignoring");
130 if (parseError.
error)
184 qCWarning(lcQrest,
"readText(): Charset \"%s\" is not supported", charset.
constData());
190 qCWarning(lcQrest,
"readText(): Decoding error occurred");
233 return status >= 200 && status < 300;
270 return wrapped->
error();
291#ifndef QT_NO_DEBUG_STREAM
310 Q_UNREACHABLE_RETURN({});
323 debug.resetFormat().nospace();
324 if (!
reply.networkReply()) {
325 debug <<
"QRestReply(no network reply)";
328 debug <<
"QRestReply(isSuccess = " <<
reply.isSuccess()
329 <<
", httpStatus = " <<
reply.httpStatus()
330 <<
", isHttpStatusSuccess = " <<
reply.isHttpStatusSuccess()
331 <<
", hasError = " <<
reply.hasError()
336 <<
", url " <<
reply.networkReply()->
url()
338 <<
", reply headers = " <<
reply.networkReply()->
headers()
350 constexpr auto is_OWS_char = [](
auto ch) {
return ch ==
' ' ||
ch ==
'\t'; };
353 while (
i <
data.size() && is_OWS_char(
data[
i]))
368 constexpr explicit operator bool()
const noexcept {
return !quotedString.
isEmpty(); }
371 if (!
data.startsWith(
'"'))
375 while (
i <
data.size()) {
383 if (
i ==
data.size())
417 return (
ch >=
'a' &&
ch <=
'z')
418 || (
ch >=
'0' &&
ch <=
'9')
419 || (
ch >=
'A' &&
ch <=
'Z');
427 constexpr explicit operator bool()
const noexcept {
return !comment.
isEmpty(); }
430 const auto invalid =
R{{},
data};
435 if (!
data.startsWith(
'('))
440 while (
i <
data.size()) {
450 if (
i ==
data.size())
475 constexpr explicit operator bool()
const noexcept {
return !
token.isEmpty(); }
489 constexpr explicit operator bool()
const noexcept {
return !
name.
isEmpty(); }
492 const auto invalid =
R{{}, {},
data};
505 if (!
data.startsWith(
'='))
536 constexpr explicit operator bool()
const noexcept {
return !
type.
isEmpty(); }
548 if (!
data.startsWith(
'/'))
563 while (
data.startsWith(
';')) {
571 if (
r.charset.empty() && !
param.value.startsWith(
'"'))
572 r.charset.assign(
param.value.begin(),
param.value.end());
602 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 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,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
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