cutelyst 3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
enginerequest.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: (C) 2017-2022 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
12#ifndef ENGINEREQUEST_H
13#define ENGINEREQUEST_H
14
15#include <Cutelyst/Headers>
16
17#include <QElapsedTimer>
18#include <QHostAddress>
19#include <QObject>
20
21namespace Cutelyst {
22
23class Engine;
24class Context;
25class CUTELYST_LIBRARY EngineRequest
26{
27 Q_GADGET
28 friend class Engine;
29
30public:
31 enum StatusFlag {
32 InitialState = 0x00,
33 FinalizedHeaders = 0x01,
34 IOWrite = 0x02,
35 Chunked = 0x04,
36 ChunkedDone = 0x08,
37 Async = 0x10,
38 Finalized = 0x20,
39 };
40 Q_DECLARE_FLAGS(Status, StatusFlag)
41
42 explicit EngineRequest();
43
44 virtual ~EngineRequest();
45
50 virtual void finalizeBody();
51
58 virtual void finalizeError();
59
64 void finalize();
65
71 virtual void finalizeCookies();
72
78 virtual bool finalizeHeaders();
79
83 qint64 write(const char *data, qint64 len);
84
85 bool webSocketHandshake(const QString &key, const QString &origin, const QString &protocol);
86
87 virtual bool webSocketSendTextMessage(const QString &message);
88
89 virtual bool webSocketSendBinaryMessage(const QByteArray &message);
90
91 virtual bool webSocketSendPing(const QByteArray &payload);
92
93 virtual bool webSocketClose(quint16 code, const QString &reason);
94
95protected:
99 virtual qint64 doWrite(const char *data, qint64 len) = 0;
100
111 virtual void processingFinished();
112
116 virtual bool writeHeaders(quint16 status, const Headers &headers) = 0;
117
118 virtual bool
119 webSocketHandshakeDo(const QString &key, const QString &origin, const QString &protocol);
120
121public:
128 void setPath(char *rawPath, const int len);
129
130 inline void setPath(const QString &path)
131 {
132 QByteArray rawPath = path.toLatin1();
133 setPath(rawPath.data(), rawPath.size());
134 }
135
138
141
144
147
152
155
158
161
163 quint64 startOfRequest = 0;
164
166 Status status = InitialState;
167
170 QIODevice *body = nullptr;
171
174 Context *context = nullptr;
175
177 quint16 remotePort = 0;
178
180 bool isSecure = false;
181
184};
185
186} // namespace Cutelyst
187
188Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
189
190#endif // ENGINEREQUEST_H
The Cutelyst Context.
Definition context.h:39
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.
QString method
The method used (GET, POST...).
quint64 startOfRequest
The timestamp of the start of request, TODO remove in Cutelyst 3.
virtual void finalizeBody()
Engines must reimplement this to write the response body back to the caller.
bool isSecure
If the connection is secure HTTPS.
virtual void finalizeError()
Engines should overwrite this if they want to to make custom error messages.
QString path
Call setPath() instead.
Status status
Connection status.
void finalize()
Called by Application to deal with finalizing cookies, headers and body.
qint64 write(const char *data, qint64 len)
Called by Response to manually write data.
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 query
The query string requested by the user agent 'foo=bar&baz'.
QHostAddress remoteAddress
The remote/client address.
quint16 remotePort
The remote/client port.
QString remoteUser
The remote user name set by a front web server.
Headers headers
The request headers.
virtual bool writeHeaders(quint16 status, const Headers &headers)=0
Reimplement this to write the headers back to the client.
QString serverAddress
The server address which the server is listening to, usually the 'Host' header but if that's not pres...
virtual bool finalizeHeaders()
Finalize the headers, and call doWriteHeader(), reimplemententions must call this first.
virtual void finalizeCookies()
Reimplement if you need a custom way to Set-Cookie, the default implementation writes them to c->res(...
QElapsedTimer elapsed
The elapsed timer since the start of request.
QIODevice * body
The QIODevice containing the body (if any) of the request.
QString protocol
The protocol requested by the user agent 'HTTP1/1'.
virtual void processingFinished()
This is called when the Application chain is finished processing this request, here the request can s...
The Cutelyst Engine.
Definition engine.h:21
The Cutelyst namespace holds all public Cutelyst API.
Definition Mainpage.dox:8
char * data()
int size() const const