9#include <Cutelyst/Context>
10#include <Cutelyst/response_p.h>
12#include <QLoggingCategory>
13Q_LOGGING_CATEGORY(CUTELYST_ENGINEREQUEST,
"cutelyst.engine_request", QtWarningMsg)
18EngineRequest::EngineRequest()
22EngineRequest::~EngineRequest()
29 if (!(
status & EngineRequest::Chunked)) {
34 if (!
body->isSequential()) {
38 char block[64 * 1024];
39 while (!
body->atEnd()) {
40 qint64 in =
body->read(block,
sizeof(block));
45 if (
write(block, in) != in) {
46 qCWarning(CUTELYST_ENGINEREQUEST) <<
"Failed to write body";
54 }
else if (!(
status & EngineRequest::ChunkedDone)) {
77 res->
setStatus(Response::InternalServerError);
90 status |= EngineRequest::Finalized;
98 const auto cookies = res->
cookies();
100 headers.pushHeader(
"Set-Cookie"_ba, cookie.toRawForm());
110 const qint64 size = response->
size();
112 headers.setContentLength(size);
118 status |= EngineRequest::FinalizedHeaders;
124 if (!(
status & EngineRequest::Chunked)) {
126 }
else if (!(
status & EngineRequest::ChunkedDone)) {
136 status |= EngineRequest::ChunkedDone;
139 return retWrite == chunk.
size() ? len : -1;
144bool EngineRequest::webSocketHandshake(
const QByteArray &key,
148 if (
status & EngineRequest::FinalizedHeaders) {
152 if (webSocketHandshakeDo(key, origin,
protocol)) {
153 status |= EngineRequest::FinalizedHeaders | EngineRequest::Async | EngineRequest::IOWrite;
163bool EngineRequest::webSocketSendTextMessage(
const QString &message)
169bool EngineRequest::webSocketSendBinaryMessage(
const QByteArray &message)
175bool EngineRequest::webSocketSendPing(
const QByteArray &payload)
181bool EngineRequest::webSocketClose(quint16 code,
const QString &reason)
192bool EngineRequest::webSocketHandshakeDo(
const QByteArray &key,
209 char *data = rawPath;
210 const char *inputPtr = data;
212 bool lastSlash =
false;
213 bool skipUtf8 =
true;
215 for (
int i = 0; i < len; ++i, ++outlen) {
216 const char c = inputPtr[i];
217 if (c ==
'%' && i + 2 < len) {
218 int a = inputPtr[++i];
219 int b = inputPtr[++i];
221 if (a >=
'0' && a <=
'9')
223 else if (a >=
'a' && a <=
'f')
225 else if (a >=
'A' && a <=
'F')
228 if (b >=
'0' && b <=
'9')
230 else if (b >=
'a' && b <=
'f')
232 else if (b >=
'A' && b <=
'F')
235 *data++ = char((a << 4) | b);
237 }
else if (c ==
'+') {
239 }
else if (c ==
'/') {
260 if (!
path.startsWith(u
'/')) {
265#include "moc_enginerequest.cpp"
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()
void setContentType(const QByteArray &type)
Headers & headers() noexcept
void setStatus(quint16 status) noexcept
void setBody(QIODevice *body)
QList< QNetworkCookie > cookies() const
QIODevice * bodyDevice() const noexcept
qint64 size() const noexcept override
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
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)