22 #include <Cutelyst/response_p.h>
23 #include <Cutelyst/Context>
25 #include <QLoggingCategory>
26 Q_LOGGING_CATEGORY(CUTELYST_ENGINEREQUEST,
"cutelyst.engine_request", QtWarningMsg)
28 using namespace Cutelyst;
35 EngineRequest::~EngineRequest()
42 if (!(
status & EngineRequest::Chunked)) {
51 char block[64 * 1024];
52 while (!body->
atEnd()) {
53 qint64 in = body->
read(block,
sizeof(block));
58 if (
write(block, in) != in) {
59 qCWarning(CUTELYST_ENGINEREQUEST) <<
"Failed to write body";
67 }
else if (!(
status & EngineRequest::ChunkedDone)) {
90 res->
setStatus(Response::InternalServerError);
103 status |= EngineRequest::Finalized;
111 const auto cookies = res->
cookies();
124 qint64 size = response->
size();
133 status |= EngineRequest::FinalizedHeaders;
139 if (!(
status & EngineRequest::Chunked)) {
141 }
else if (!(
status & EngineRequest::ChunkedDone)) {
152 status |= EngineRequest::ChunkedDone;
155 return retWrite == chunk.
size() ? len : -1;
160 bool EngineRequest::webSocketHandshake(
const QString &key,
const QString &origin,
const QString &protocol)
162 if (
status & EngineRequest::FinalizedHeaders) {
166 if (webSocketHandshakeDo(key, origin, protocol)) {
167 status |= EngineRequest::FinalizedHeaders | EngineRequest::Async | EngineRequest::IOWrite;
177 bool EngineRequest::webSocketSendTextMessage(
const QString &message)
206 bool EngineRequest::webSocketHandshakeDo(
const QString &key,
const QString &origin,
const QString &protocol)
221 char *data = rawPath;
222 const char *inputPtr = data;
224 bool skipUtf8 =
true;
226 for (
int i = 0; i < len; ++i, ++outlen) {
227 const char c = inputPtr[i];
228 if (c ==
'%' && i + 2 < len) {
229 int a = inputPtr[++i];
230 int b = inputPtr[++i];
232 if (a >=
'0' && a <=
'9') a -=
'0';
233 else if (a >=
'a' && a <=
'f') a = a -
'a' + 10;
234 else if (a >=
'A' && a <=
'F') a = a -
'A' + 10;
236 if (b >=
'0' && b <=
'9') b -=
'0';
237 else if (b >=
'a' && b <=
'f') b = b -
'a' + 10;
238 else if (b >=
'A' && b <=
'F') b = b -
'A' + 10;
240 *data++ = char((a << 4) | b);
242 }
else if (c ==
'+') {
256 #include "moc_enginerequest.cpp"
QString path
Call setPath() instead.
void setContentType(const QString &type)
virtual bool atEnd() const
virtual bool seek(qint64 pos)
QByteArray toUpper() const
QIODevice * body
The QIODevice containing the body (if any) of the request.
qint64 write(const char *data, qint64 len)
Called by Response to manually write data.
virtual qint64 size() const override
QString join(const QString &separator) const
void setStatus(quint16 status)
bool error() const
Returns true if an error was set.
QList< QNetworkCookie > cookies() const
virtual void finalizeError()
Engines should overwrite this if they want to to make custom error messages.
virtual bool isSequential() const
QString fromUtf8(const char *str, int size)
virtual qint64 doWrite(const char *data, qint64 len)=0
Reimplement this to do the RAW writing to the client.
Context * context
The Cutelyst::Context of this request.
QByteArray number(int n, int base)
const char * constData() const
Headers headers
The request headers.
qint64 read(char *data, qint64 maxSize)
void setPath(char *rawPath, const int len)
This method sets the path and already does the decoding so that it is done a single time...
QStringList errors() const
Returns a list of errors that were defined.
QByteArray & append(char ch)
Response * response() const
virtual bool finalizeHeaders()
Finalize the headers, and call doWriteHeader(), reimplemententions must call this first...
Q_REQUIRED_RESULT QByteArray & body()
Status status
Connection status.
QIODevice * bodyDevice() const
QString fromLatin1(const char *str, int size)
void setBody(QIODevice *body)
virtual void finalizeBody()
Engines must reimplement this to write the response body back to the caller.
virtual bool writeHeaders(quint16 status, const Headers &headers)=0
Reimplement this to write the headers back to the client.
virtual void finalizeCookies()
Reimplement if you need a custom way to Set-Cookie, the default implementation writes them to c->res(...
void finalize()
Called by Application to deal with finalizing cookies, headers and body.
void finalize()
finalize the request right away this is automatically called at the end of the actions chain ...
virtual void processingFinished()
This is called when the Application chain is finished processing this request, here the request can s...
QByteArray toUtf8() const