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 
21 namespace Cutelyst {
22 
23 class Engine;
24 class Context;
25 class CUTELYST_LIBRARY EngineRequest
26 {
27  Q_GADGET
28  friend class Engine;
29 
30 public:
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 
95 protected:
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 
121 public:
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 
188 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
189 
190 #endif // ENGINEREQUEST_H
QString path
Call setPath() instead.
QString protocol
The protocol requested by the user agent &#39;HTTP1/1&#39;.
QElapsedTimer elapsed
The elapsed timer since the start of request.
QString remoteUser
The remote user name set by a front web server.
The Cutelyst Context.
Definition: context.h:38
Headers headers
The request headers.
QHostAddress remoteAddress
The remote/client address.
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
QString method
The method used (GET, POST...)
QByteArray toLatin1() const const
char * data()
QString serverAddress
The server address which the server is listening to, usually the &#39;Host&#39; header but if that&#39;s not pres...
QByteArray query
The query string requested by the user agent &#39;foo=bar&baz&#39;.
int size() const const
The Cutelyst Engine
Definition: engine.h:20