5 #ifndef CUTELYST_RESPONSE_H
6 #define CUTELYST_RESPONSE_H
8 #include <QtCore/QIODevice>
10 #include <Cutelyst/cutelyst_global.h>
11 #include <Cutelyst/headers.h>
20 class ResponsePrivate;
21 class CUTELYST_LIBRARY
Response final :
public QIODevice
29 SwitchingProtocols = 101,
33 NonAuthoritativeInformation = 203,
38 MultipleChoices = 300,
39 MovedPermanently = 301,
44 TemporaryRedirect = 307,
45 PermanentRedirect = 308,
48 PaymentRequired = 402,
51 MethodNotAllowed = 405,
53 ProxyAuthenticationRequired = 407,
58 PreconditionFailed = 412,
59 RequestEntityTooLarge = 413,
60 RequestURITooLong = 414,
61 UnsupportedMediaType = 415,
62 RequestedRangeNotSatisfiable = 416,
63 ExpectationFailed = 417,
64 InternalServerError = 500,
67 ServiceUnavailable = 503,
69 HTTPVersionNotSupported = 505,
70 BandwidthLimitExceeded = 509
76 CloseCodeNormal = 1000,
77 CloseCodeGoingAway = 1001,
78 CloseCodeProtocolError = 1002,
79 CloseCodeDatatypeNotSupported = 1003,
80 CloseCodeReserved1004 = 1004,
81 CloseCodeMissingStatusCode = 1005,
82 CloseCodeAbnormalDisconnection = 1006,
83 CloseCodeWrongDatatype = 1007,
84 CloseCodePolicyViolated = 1008,
85 CloseCodeTooMuchData = 1009,
86 CloseCodeMissingExtension = 1010,
87 CloseCodeBadOperation = 1011,
88 CloseCodeTlsHandshakeFailed = 1015
97 quint16 status() const noexcept;
102 void setStatus(quint16 status) noexcept;
109 bool hasBody() const noexcept;
117 Q_REQUIRED_RESULT QByteArray &body();
122 QIODevice *bodyDevice() const;
130 void setBody(QIODevice *body);
136 void setBody(const QByteArray &body);
142 inline
void setBody(const QString &body);
148 inline
void setBody(QStringView body);
155 void setJsonBody(const QJsonDocument &documment);
161 void setJsonBody(const QString &json);
167 inline
void setJsonBody(QStringView json);
173 void setJsonBody(const QByteArray &json);
180 void setJsonObjectBody(const QJsonObject &
object);
187 void setJsonArrayBody(const QJsonArray &array);
192 QString contentEncoding() const;
197 void setContentEncoding(const QString &encoding);
202 qint64 contentLength() const;
207 void setContentLength(qint64 length);
212 QString contentType() const;
217 void setContentType(const QString &type)
218 { headers().setContentType(type); }
223 QString contentTypeCharset()
const;
229 QVariant cookie(
const QByteArray &name)
const;
234 QList<QNetworkCookie> cookies()
const;
240 void setCookie(
const QNetworkCookie &cookie);
246 void setCookies(
const QList<QNetworkCookie> &cookies);
252 int removeCookies(
const QByteArray &name);
266 void redirect(
const QUrl &url, quint16 status = Found);
280 void redirect(
const QString &url, quint16 status = Found);
309 QString header(const QString &field) const;
314 void setHeader(const QString &field, const QString &value);
324 bool isFinalizedHeaders() const noexcept;
329 virtual
bool isSequential() const noexcept override;
334 virtual qint64 size() const noexcept override;
346 bool webSocketHandshake(const QString &key = {},
const QString &origin = {},
const QString &protocol = {});
375 bool webSocketClose(quint16 code = Response::CloseCodeNormal,
const QString &reason = {});
390 virtual qint64 writeData(
const char *data, qint64 len)
override;
395 virtual qint64 readData(
char *data, qint64 maxlen)
override;
397 ResponsePrivate *d_ptr;
400 friend class EngineConnection;
402 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(const QJsonDocument &documment)
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.