Cutelyst  3.5.0
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 
135 
138 
141 
144 
148 
151 
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 
180 };
181 
182 }
183 
184 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
185 
186 #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