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;
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;
142 inline
void setBody(const
QString &body);
155 void setJsonBody(const
QString &json);
175 void setJsonArrayBody(const
QJsonArray &array);
180 QString contentEncoding() const;
185 void setContentEncoding(const
QString &encoding);
190 qint64 contentLength() const;
195 void setContentLength(qint64 length);
206 { headers().setContentType(type); }
211 QString contentTypeCharset()
const;
254 void redirect(
const QUrl &url, quint16 status = Found);
268 void redirect(
const QString &url, quint16 status = Found);
287 void redirectSafe(
const QUrl &url,
const QUrl &fallback);
292 QUrl location() const noexcept;
312 bool isFinalizedHeaders() const noexcept;
317 virtual
bool isSequential() const noexcept override;
322 virtual qint64 size() const noexcept override;
334 bool webSocketHandshake(const
QString &key = {},
const QString &origin = {},
const QString &protocol = {});
339 bool webSocketTextMessage(
const QString &message);
344 bool webSocketBinaryMessage(
const QByteArray &message);
354 bool webSocketPing(
const QByteArray &payload = {});
363 bool webSocketClose(quint16 code = Response::CloseCodeNormal,
const QString &reason = {});
369 explicit Response(
const Headers &defaultHeaders, EngineRequest *conn =
nullptr);
378 virtual qint64 writeData(
const char *data, qint64 len)
override;
383 virtual qint64 readData(
char *data, qint64 maxlen)
override;
385 ResponsePrivate *d_ptr;
386 friend class Application;
388 friend class EngineConnection;
389 friend class Context;
390 friend class ContextPrivate;
399 #endif // CUTELYST_RESPONSE_H
The Cutelyst namespace holds all public Cutelyst API.
void setBody(QIODevice *body)
QByteArray toUtf8() const const