24class CUTELYST_LIBRARY
Response final :
public QIODevice
32 SwitchingProtocols = 101,
36 NonAuthoritativeInformation = 203,
41 MultipleChoices = 300,
42 MovedPermanently = 301,
47 TemporaryRedirect = 307,
48 PermanentRedirect = 308,
51 PaymentRequired = 402,
54 MethodNotAllowed = 405,
56 ProxyAuthenticationRequired = 407,
61 PreconditionFailed = 412,
62 RequestEntityTooLarge = 413,
63 RequestURITooLong = 414,
64 UnsupportedMediaType = 415,
65 RequestedRangeNotSatisfiable = 416,
66 ExpectationFailed = 417,
67 InternalServerError = 500,
70 ServiceUnavailable = 503,
72 HTTPVersionNotSupported = 505,
73 BandwidthLimitExceeded = 509
79 CloseCodeNormal = 1000,
80 CloseCodeGoingAway = 1001,
81 CloseCodeProtocolError = 1002,
82 CloseCodeDatatypeNotSupported = 1003,
83 CloseCodeReserved1004 = 1004,
84 CloseCodeMissingStatusCode = 1005,
85 CloseCodeAbnormalDisconnection = 1006,
86 CloseCodeWrongDatatype = 1007,
87 CloseCodePolicyViolated = 1008,
88 CloseCodeTooMuchData = 1009,
89 CloseCodeMissingExtension = 1010,
90 CloseCodeBadOperation = 1011,
91 CloseCodeTlsHandshakeFailed = 1015
100 quint16 status() const noexcept;
105 void setStatus(quint16 status) noexcept;
112 bool hasBody() const noexcept;
120 Q_REQUIRED_RESULT QByteArray &body();
125 QIODevice *bodyDevice() const;
133 void setBody(QIODevice *body);
139 void setBody(const QByteArray &body);
145 inline
void setBody(const QString &body);
151 inline
void setBody(QStringView body);
158 void setJsonBody(const QJsonDocument &documment);
164 void setJsonBody(const QString &json);
170 inline
void setJsonBody(QStringView json);
176 void setJsonBody(const QByteArray &json);
183 void setJsonObjectBody(const QJsonObject &
object);
190 void setJsonArrayBody(const QJsonArray &array);
195 QString contentEncoding() const;
200 void setContentEncoding(const QString &encoding);
205 qint64 contentLength() const;
210 void setContentLength(qint64 length);
215 QString contentType() const;
225 QString contentTypeCharset()
const;
231 QVariant cookie(
const QByteArray &name)
const;
233#if (QT_VERSION < QT_VERSION_CHECK(6, 1, 0))
240 QVariant cuteCookie(
const QByteArray &name)
const;
246 QList<QNetworkCookie> cookies()
const;
248#if (QT_VERSION < QT_VERSION_CHECK(6, 1, 0))
254 QList<Cookie> cuteCookies()
const;
261 void setCookie(
const QNetworkCookie &cookie);
263#if (QT_VERSION < QT_VERSION_CHECK(6, 1, 0))
270 void setCuteCookie(
const Cookie &cookie);
277 void setCookies(
const QList<QNetworkCookie> &cookies);
279#if (QT_VERSION < QT_VERSION_CHECK(6, 1, 0))
286 void setCuteCookies(
const QList<Cookie> &cookies);
293 int removeCookies(
const QByteArray &name);
295#if (QT_VERSION < QT_VERSION_CHECK(6, 1, 0))
302 int removeCuteCookies(
const QByteArray &name);
317 void redirect(
const QUrl &url, quint16 status = Found);
360 QString
header(const QString &field) const;
365 void setHeader(const QString &field, const QString &value);
385 virtual qint64
size() const noexcept override;
398 const QString &origin = {},
399 const QString &protocol = {});
428 bool webSocketClose(quint16 code = Response::CloseCodeNormal,
const QString &reason = {});
443 virtual qint64 writeData(
const char *data, qint64 len)
override;
448 virtual qint64 readData(
char *data, qint64 maxlen)
override;
450 ResponsePrivate *d_ptr;
453 friend class EngineConnection;
455 friend class ContextPrivate;
bool webSocketHandshake(const QString &key={}, const QString &origin={}, const QString &protocol={})
Sends the websocket handshake, if no parameters are defined it will use header data.
bool webSocketClose(quint16 code=Response::CloseCodeNormal, const QString &reason={})
Sends a WebSocket close frame, with both optional close code and a string reason.