9 #include <Cutelyst/Context> 10 #include <Cutelyst/response_p.h> 12 #include <QLoggingCategory> 13 Q_LOGGING_CATEGORY(CUTELYST_ENGINEREQUEST,
"cutelyst.engine_request", QtWarningMsg)
17 EngineRequest::EngineRequest()
21 EngineRequest::~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();
101 #if (QT_VERSION < QT_VERSION_CHECK(6, 1, 0)) 102 const auto cuteCookies = res->cuteCookies();
103 for (
const Cookie &cookie : cuteCookies) {
116 qint64 size = response->
size();
125 status |= EngineRequest::FinalizedHeaders;
131 if (!(
status & EngineRequest::Chunked)) {
133 }
else if (!(
status & EngineRequest::ChunkedDone)) {
143 status |= EngineRequest::ChunkedDone;
146 return retWrite == chunk.
size() ? len : -1;
151 bool EngineRequest::webSocketHandshake(
const QString &key,
155 if (
status & EngineRequest::FinalizedHeaders) {
159 if (webSocketHandshakeDo(key, origin,
protocol)) {
160 status |= EngineRequest::FinalizedHeaders | EngineRequest::Async | EngineRequest::IOWrite;
170 bool EngineRequest::webSocketSendTextMessage(
const QString &message)
176 bool EngineRequest::webSocketSendBinaryMessage(
const QByteArray &message)
182 bool EngineRequest::webSocketSendPing(
const QByteArray &payload)
188 bool EngineRequest::webSocketClose(quint16 code,
const QString &reason)
199 bool EngineRequest::webSocketHandshakeDo(
const QString &key,
216 char *data = rawPath;
217 const char *inputPtr = data;
219 bool skipUtf8 =
true;
221 for (
int i = 0; i < len; ++i, ++outlen) {
222 const char c = inputPtr[i];
223 if (c ==
'%' && i + 2 < len) {
224 int a = inputPtr[++i];
225 int b = inputPtr[++i];
227 if (a >=
'0' && a <=
'9')
229 else if (a >=
'a' && a <=
'f')
231 else if (a >=
'A' && a <=
'F')
234 if (b >=
'0' && b <=
'9')
236 else if (b >=
'a' && b <=
'f')
238 else if (b >=
'A' && b <=
'F')
241 *data++ = char((a << 4) | b);
243 }
else if (c ==
'+') {
257 #include "moc_enginerequest.cpp"
QString path
Call setPath() instead.
void setContentType(const QString &type)
virtual bool atEnd() const const
QString protocol
The protocol requested by the user agent 'HTTP1/1'.
bool error() const noexcept
Returns true if an error was set.
virtual bool seek(qint64 pos)
Headers & headers() noexcept
QByteArray toUpper() const 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.
QString join(const QString &separator) const const
virtual void finalizeError()
Engines should overwrite this if they want to to make custom error messages.
virtual bool isSequential() const 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.
QList< QNetworkCookie > cookies() const
Context * context
The Cutelyst::Context of this request.
QByteArray number(int n, int base)
const char * constData() const const
Headers headers
The request headers.
qint64 read(char *data, qint64 maxSize)
The Cutelyst namespace holds all public Cutelyst API.
virtual qint64 size() const noexcept override
quint16 status() const noexcept
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...
QByteArray & append(char ch)
virtual bool finalizeHeaders()
Finalize the headers, and call doWriteHeader(), reimplemententions must call this first...
Q_REQUIRED_RESULT QByteArray & body()
Status status
Connection status.
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.
Response * response() const noexcept
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 setStatus(quint16 status) noexcept
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...
QStringList errors() const noexcept
Returns a list of errors that were defined.
QIODevice * bodyDevice() const
QByteArray toUtf8() const const