22 #include <Cutelyst/response_p.h>
23 #include <Cutelyst/Context>
25 #include <QLoggingCategory>
26 Q_LOGGING_CATEGORY(CUTELYST_ENGINEREQUEST,
"cutelyst.engine_request", QtWarningMsg)
30 EngineRequest::EngineRequest()
35 EngineRequest::~EngineRequest()
42 if (!(
status & EngineRequest::Chunked)) {
51 char block[64 * 1024];
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)
183 bool EngineRequest::webSocketSendBinaryMessage(
const QByteArray &message)
189 bool EngineRequest::webSocketSendPing(
const QByteArray &payload)
195 bool EngineRequest::webSocketClose(quint16 code,
const QString &reason)
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"
Status status
Connection status.
QString fromUtf8(const char *str, int size)
virtual qint64 size() const override
void setStatus(quint16 status)
QByteArray & append(char ch)
QList< QNetworkCookie > cookies() const
QByteArray number(int n, int base)
virtual bool seek(qint64 pos)
Response * response() const
Headers headers
The request headers.
virtual void finalizeBody()
Engines must reimplement this to write the response body back to the caller.
void setContentType(const QString &type)
virtual bool finalizeHeaders()
Finalize the headers, and call doWriteHeader(), reimplemententions must call this first.
void setBody(QIODevice *body)
QString path
Call setPath() instead.
QString protocol
The protocol requested by the user agent 'HTTP1/1'.
virtual bool isSequential() const const
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(...
virtual void processingFinished()
This is called when the Application chain is finished processing this request, here the request can s...
bool error() const
Returns true if an error was set.
QString join(const QString &separator) const const
QByteArray toUpper() const const
Context * context
The Cutelyst::Context of this request.
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.
QIODevice * bodyDevice() const
qint64 read(char *data, qint64 maxSize)
QStringList errors() const
Returns a list of errors that were defined.
The Cutelyst namespace holds all public Cutelyst API.
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.
const char * constData() const const
void finalize()
finalize the request right away this is automatically called at the end of the actions chain
QString fromLatin1(const char *str, int size)
virtual bool atEnd() const const
virtual qint64 doWrite(const char *data, qint64 len)=0
Reimplement this to do the RAW writing to the client.
virtual void finalizeError()
Engines should overwrite this if they want to to make custom error messages.
void finalize()
Called by Application to deal with finalizing cookies, headers and body.
Q_REQUIRED_RESULT QByteArray & body()