cutelyst  3.7.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-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 <QObject>
16 #include <QHostAddress>
17 #include <QElapsedTimer>
18 
19 #include <Cutelyst/Headers>
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 public:
30  enum StatusFlag {
31  InitialState = 0x00,
32  FinalizedHeaders = 0x01,
33  IOWrite = 0x02,
34  Chunked = 0x04,
35  ChunkedDone = 0x08,
36  Async = 0x10,
37  Finalized = 0x20,
38  };
39  Q_DECLARE_FLAGS(Status, StatusFlag)
40 
41  explicit EngineRequest();
42 
43  virtual ~EngineRequest();
44 
49  virtual void finalizeBody();
50 
57  virtual void finalizeError();
58 
63  void finalize();
64 
70  virtual void finalizeCookies();
71 
77  virtual bool finalizeHeaders();
78 
82  qint64 write(const char *data, qint64 len);
83 
84  bool webSocketHandshake(const QString &key, const QString &origin, const QString &protocol);
85 
86  virtual bool webSocketSendTextMessage(const QString &message);
87 
88  virtual bool webSocketSendBinaryMessage(const QByteArray &message);
89 
90  virtual bool webSocketSendPing(const QByteArray &payload);
91 
92  virtual bool webSocketClose(quint16 code, const QString &reason);
93 
94 protected:
98  virtual qint64 doWrite(const char *data, qint64 len) = 0;
99 
110  virtual void processingFinished();
111 
115  virtual bool writeHeaders(quint16 status, const Headers &headers) = 0;
116 
117  virtual bool webSocketHandshakeDo(const QString &key, const QString &origin, const QString &protocol);
118 
119 public:
126  void setPath(char *rawPath, const int len);
127 
128  inline void setPath(const QString &path) {
129  QByteArray rawPath = path.toLatin1();
130  setPath(rawPath.data(), rawPath.size());
131  }
132 
134  QString method;
135 
137  QString path;
138 
140  QByteArray query;
141 
143  QString protocol;
144 
147  QString serverAddress;
148 
150  QHostAddress remoteAddress;
151 
153  QString remoteUser;
154 
157 
159  quint64 startOfRequest = 0;
160 
162  Status status = InitialState;
163 
166  QIODevice *body = nullptr;
167 
170  Context *context = nullptr;
171 
173  quint16 remotePort = 0;
174 
176  bool isSecure = false;
177 
179  QElapsedTimer elapsed;
180 };
181 
182 }
183 
184 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
185 
186 #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.
QString method
The method used (GET, POST...)
QString path
Call setPath() instead.
QByteArray query
The query string requested by the user agent 'foo=bar&baz'.
QHostAddress remoteAddress
The remote/client address.
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...
QElapsedTimer elapsed
The elapsed timer since the start of request.
QString protocol
The protocol requested by the user agent 'HTTP1/1'.
The Cutelyst Engine.
Definition: engine.h:21
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8