9#include <Cutelyst/Context>
10#include <Cutelyst/response_p.h>
12#include <QLoggingCategory>
13Q_LOGGING_CATEGORY(CUTELYST_ENGINEREQUEST,
"cutelyst.engine_request", QtWarningMsg)
17EngineRequest::EngineRequest()
21EngineRequest::~EngineRequest()
28 if (!(
status & EngineRequest::Chunked)) {
37 char block[64 * 1024];
39 qint64 in =
body->
read(block,
sizeof(block));
44 if (
write(block, in) != in) {
45 qCWarning(CUTELYST_ENGINEREQUEST) <<
"Failed to write body";
53 }
else if (!(
status & EngineRequest::ChunkedDone)) {
76 res->
setStatus(Response::InternalServerError);
89 status |= EngineRequest::Finalized;
97 const auto cookies = res->
cookies();
109 const qint64 size = response->
size();
117 status |= EngineRequest::FinalizedHeaders;
123 if (!(
status & EngineRequest::Chunked)) {
125 }
else if (!(
status & EngineRequest::ChunkedDone)) {
135 status |= EngineRequest::ChunkedDone;
138 return retWrite == chunk.
size() ? len : -1;
143bool EngineRequest::webSocketHandshake(
const QByteArray &key,
147 if (
status & EngineRequest::FinalizedHeaders) {
151 if (webSocketHandshakeDo(key, origin,
protocol)) {
152 status |= EngineRequest::FinalizedHeaders | EngineRequest::Async | EngineRequest::IOWrite;
162bool EngineRequest::webSocketSendTextMessage(
const QString &message)
168bool EngineRequest::webSocketSendBinaryMessage(
const QByteArray &message)
174bool EngineRequest::webSocketSendPing(
const QByteArray &payload)
180bool EngineRequest::webSocketClose(quint16 code,
const QString &reason)
191bool EngineRequest::webSocketHandshakeDo(
const QByteArray &key,
208 char *data = rawPath;
209 const char *inputPtr = data;
211 bool lastSlash =
false;
212 bool skipUtf8 =
true;
214 for (
int i = 0; i < len; ++i, ++outlen) {
215 const char c = inputPtr[i];
216 if (c ==
'%' && i + 2 < len) {
217 int a = inputPtr[++i];
218 int b = inputPtr[++i];
220 if (a >=
'0' && a <=
'9')
222 else if (a >=
'a' && a <=
'f')
224 else if (a >=
'A' && a <=
'F')
227 if (b >=
'0' && b <=
'9')
229 else if (b >=
'a' && b <=
'f')
231 else if (b >=
'A' && b <=
'F')
234 *data++ = char((a << 4) | b);
236 }
else if (c ==
'+') {
238 }
else if (c ==
'/') {
264#include "moc_enginerequest.cpp"
QStringList errors() const noexcept
bool error() const noexcept
Response * response() const noexcept
virtual qint64 doWrite(const char *data, qint64 len)=0
virtual void finalizeBody()
virtual void finalizeError()
qint64 write(const char *data, qint64 len)
void setPath(char *rawPath, const int len)
virtual bool writeHeaders(quint16 status, const Headers &headers)=0
virtual bool finalizeHeaders()
virtual void finalizeCookies()
virtual void processingFinished()
qint64 size() const noexcept override
void setContentType(const QByteArray &type)
void setStatus(quint16 status) noexcept
void setBody(QIODevice *body)
Headers & headers() noexcept
QList< QNetworkCookie > cookies() const
QIODevice * bodyDevice() const noexcept
quint16 status() const noexcept
The Cutelyst namespace holds all public Cutelyst API.
QByteArray & append(QByteArrayView data)
const char * constData() const const
QByteArray number(double n, char format, int precision)
void reserve(qsizetype size)
qsizetype size() const const
QByteArray toUpper() const const
virtual bool atEnd() const const
virtual bool isSequential() const const
QByteArray read(qint64 maxSize)
virtual bool seek(qint64 pos)
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
QString & prepend(QChar ch)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const