7#include <Cutelyst/cutelyst_global.h>
8#include <Cutelyst/headers.h>
10#include <QtCore/QIODevice>
20class CUTELYST_LIBRARY
Response final :
public QIODevice
28 SwitchingProtocols = 101,
32 NonAuthoritativeInformation = 203,
37 MultipleChoices = 300,
38 MovedPermanently = 301,
43 TemporaryRedirect = 307,
44 PermanentRedirect = 308,
47 PaymentRequired = 402,
50 MethodNotAllowed = 405,
52 ProxyAuthenticationRequired = 407,
57 PreconditionFailed = 412,
58 RequestEntityTooLarge = 413,
59 RequestURITooLong = 414,
60 UnsupportedMediaType = 415,
61 RequestedRangeNotSatisfiable = 416,
62 ExpectationFailed = 417,
63 InternalServerError = 500,
66 ServiceUnavailable = 503,
68 HTTPVersionNotSupported = 505,
69 BandwidthLimitExceeded = 509
75 CloseCodeNormal = 1000,
76 CloseCodeGoingAway = 1001,
77 CloseCodeProtocolError = 1002,
78 CloseCodeDatatypeNotSupported = 1003,
79 CloseCodeReserved1004 = 1004,
80 CloseCodeMissingStatusCode = 1005,
81 CloseCodeAbnormalDisconnection = 1006,
82 CloseCodeWrongDatatype = 1007,
83 CloseCodePolicyViolated = 1008,
84 CloseCodeTooMuchData = 1009,
85 CloseCodeMissingExtension = 1010,
86 CloseCodeBadOperation = 1011,
87 CloseCodeTlsHandshakeFailed = 1015
96 quint16 status() const noexcept;
101 void setStatus(quint16 status) noexcept;
108 bool hasBody() const noexcept;
116 [[nodiscard]] QByteArray &body();
121 QIODevice *bodyDevice() const noexcept;
129 void setBody(QIODevice *body);
135 void setBody(const QByteArray &body);
141 inline
void setBody(const QString &body);
147 inline
void setBody(QStringView body);
153 inline
void setJsonBody(QStringView json);
159 void setJsonBody(const QByteArray &json);
166 void setJsonObjectBody(const QJsonObject &obj);
173 void setJsonArrayBody(const QJsonArray &array);
178 QByteArray contentEncoding() const noexcept;
183 void setContentEncoding(const QByteArray &encoding);
188 qint64 contentLength() const;
193 void setContentLength(qint64 length);
198 QByteArray contentType() const;
203 void setContentType(const QByteArray &type) { headers().setContentType(type); }
208 QByteArray contentTypeCharset()
const;
214 QVariant cookie(
const QByteArray &name)
const;
219 QList<QNetworkCookie> cookies()
const;
225 void setCookie(
const QNetworkCookie &cookie);
231 void setCookies(
const QList<QNetworkCookie> &cookies);
237 int removeCookies(
const QByteArray &name);
251 void redirect(
const QUrl &url, quint16 status = Found);
265 void redirect(
const QString &url, quint16 status = Found);
294 QByteArray header(const QByteArray &field) const noexcept;
299 void setHeader(const QByteArray &key, const QByteArray &value);
309 bool isFinalizedHeaders() const noexcept;
314 bool isSequential() const noexcept override;
319 qint64 size() const noexcept override;
331 bool webSocketHandshake(const QByteArray &key = {},
332 const QByteArray &origin = {},
333 const QByteArray &protocol = {});
362 bool webSocketClose(quint16 code = Response::CloseCodeNormal,
const QString &reason = {});
377 virtual qint64 writeData(
const char *data, qint64 len)
override;
382 virtual qint64 readData(
char *data, qint64 maxlen)
override;
384 ResponsePrivate *d_ptr;
387 friend class EngineConnection;
389 friend class ContextPrivate;
The Cutelyst Application.
bool webSocketTextMessage(const QString &message)
Sends a WebSocket text message.
bool webSocketPing(const QByteArray &payload={})
Sends a WebSocket ping with an optional payload limited to 125 bytes, which will be truncated if larg...
void setBody(QIODevice *body)
void redirectSafe(const QUrl &url, const QUrl &fallback)
bool webSocketBinaryMessage(const QByteArray &message)
Sends a WebSocket binary message.
void redirect(const QString &url, quint16 status=Found)
void setJsonBody(QStringView json)
bool webSocketClose(quint16 code=Response::CloseCodeNormal, const QString &reason={})
Sends a WebSocket close frame, with both optional close code and a string reason.
QUrl location() const noexcept
The Cutelyst namespace holds all public Cutelyst API.