cutelyst 4.3.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
143
146
149
152
157
160
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:42
virtual qint64 doWrite(const char *data, qint64 len)=0
TimePointSteady startOfRequest
virtual bool writeHeaders(quint16 status, const Headers &headers)=0
The Cutelyst Engine.
Definition engine.h:20
Container for HTTP headers.
Definition headers.h:24
The Cutelyst namespace holds all public Cutelyst API.
char * data()
qsizetype size() const const
bool startsWith(QByteArrayView bv) const const