cutelyst 4.0.0
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-2023 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
12#pragma once
13
14#include <Cutelyst/Headers>
15#include <chrono>
16
17#include <QElapsedTimer>
18#include <QHostAddress>
19#include <QObject>
20
21namespace Cutelyst {
22
23using TimePointSteady = std::chrono::time_point<std::chrono::steady_clock>;
24
25class Engine;
26class Context;
27class CUTELYST_LIBRARY EngineRequest
28{
29 Q_GADGET
30 friend class Engine;
31
32public:
33 enum StatusFlag : quint8 {
34 InitialState = 0x00,
35 FinalizedHeaders = 0x01,
36 IOWrite = 0x02,
37 Chunked = 0x04,
38 ChunkedDone = 0x08,
39 Async = 0x10,
40 Finalized = 0x20,
41 };
42 Q_DECLARE_FLAGS(Status, StatusFlag)
43
44 explicit EngineRequest();
45
46 virtual ~EngineRequest();
47
52 virtual void finalizeBody();
53
60 virtual void finalizeError();
61
66 void finalize();
67
73 virtual void finalizeCookies();
74
80 virtual bool finalizeHeaders();
81
85 qint64 write(const char *data, qint64 len);
86
87 bool webSocketHandshake(const QByteArray &key,
88 const QByteArray &origin,
89 const QByteArray &protocol);
90
91 virtual bool webSocketSendTextMessage(const QString &message);
92
93 virtual bool webSocketSendBinaryMessage(const QByteArray &message);
94
95 virtual bool webSocketSendPing(const QByteArray &payload);
96
97 virtual bool webSocketClose(quint16 code, const QString &reason);
98
99protected:
103 virtual qint64 doWrite(const char *data, qint64 len) = 0;
104
115 virtual void processingFinished();
116
120 virtual bool writeHeaders(quint16 status, const Headers &headers) = 0;
121
122 virtual bool webSocketHandshakeDo(const QByteArray &key,
123 const QByteArray &origin,
124 const QByteArray &protocol);
125
126public:
133 void setPath(char *rawPath, const int len);
134
135 inline void setPath(QByteArray &path)
136 {
137 Q_ASSERT_X(path.startsWith('/'), "leading slash", "Path must always start with /");
138 setPath(path.data(), path.size());
139 }
140
142 QByteArray method;
143
145 QString path;
146
148 QByteArray query;
149
151 QByteArray protocol;
152
156 QByteArray serverAddress;
157
159 QHostAddress remoteAddress;
160
162 QString remoteUser;
163
166
169 QIODevice *body = nullptr;
170
173 Context *context = nullptr;
174
176 TimePointSteady startOfRequest;
177
179 quint16 remotePort = 0;
180
182 Status status = InitialState;
183
185 bool isSecure = false;
186};
187
188} // namespace Cutelyst
189
190Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
The Cutelyst Context.
Definition: context.h:38
virtual qint64 doWrite(const char *data, qint64 len)=0
Reimplement this to do the RAW writing to the client.
QString path
Call setPath() instead.
QByteArray query
The query string requested by the user agent 'foo=bar&baz'.
QHostAddress remoteAddress
The remote/client address.
QByteArray protocol
The protocol requested by the user agent 'HTTP1/1'.
QString remoteUser
The remote user name set by a front web server.
TimePointSteady startOfRequest
The timepoint of the start of request.
QByteArray method
The method used (GET, POST...)
QByteArray serverAddress
The server address which the server is listening to, usually the 'Host' header but if that's not pres...
Headers headers
The request headers.
virtual bool writeHeaders(quint16 status, const Headers &headers)=0
Reimplement this to write the headers back to the client.
The Cutelyst Engine.
Definition: engine.h:20
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8