Cutelyst  2.12.0
enginerequest.h
1 /*
2  * Copyright (C) 2017 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef ENGINEREQUEST_H
19 #define ENGINEREQUEST_H
20 
21 #include <QObject>
22 #include <QHostAddress>
23 #include <QElapsedTimer>
24 
25 #include <Cutelyst/Headers>
26 
27 namespace Cutelyst {
28 
29 class Engine;
30 class Context;
31 class CUTELYST_LIBRARY EngineRequest
32 {
33  Q_GADGET
34  friend class Engine;
35 public:
36  enum StatusFlag {
37  InitialState = 0x00,
38  FinalizedHeaders = 0x01,
39  IOWrite = 0x02,
40  Chunked = 0x04,
41  ChunkedDone = 0x08,
42  Async = 0x10,
43  };
44  Q_DECLARE_FLAGS(Status, StatusFlag)
45 
46  explicit EngineRequest();
47 
48  virtual ~EngineRequest();
49 
54  virtual void finalizeBody();
55 
62  virtual void finalizeError();
63 
68  void finalize();
69 
75  virtual void finalizeCookies();
76 
82  virtual bool finalizeHeaders();
83 
87  qint64 write(const char *data, qint64 len);
88 
89  bool webSocketHandshake(const QString &key, const QString &origin, const QString &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 
99 protected:
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 QString &key, const QString &origin, const QString &protocol);
123 
124 public:
131  void setPath(char *rawPath, const int len);
132 
133  inline void setPath(const QString &path) {
134  QByteArray rawPath = path.toLatin1();
135  setPath(rawPath.data(), rawPath.size());
136  }
137 
139  QString method;
140 
142  QString path;
143 
145  QByteArray query;
146 
148  QString protocol;
149 
152  QString serverAddress;
153 
155  QHostAddress remoteAddress;
156 
158  QString remoteUser;
159 
162 
164  quint64 startOfRequest = 0;
165 
167  Status status = InitialState;
168 
171  QIODevice *body = nullptr;
172 
175  Context *context = nullptr;
176 
178  quint16 remotePort = 0;
179 
181  bool isSecure = false;
182 
184  QElapsedTimer elapsed;
185 };
186 
187 }
188 
189 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
190 
191 #endif // ENGINEREQUEST_H
QString path
Call setPath() instead.
QString protocol
The protocol requested by the user agent 'HTTP1/1'.
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:50
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...)
QString serverAddress
The server address which the server is listening to, usually the 'Host' header but if that's not pres...
QByteArray query
The query string requested by the user agent 'foo=bar&baz'.
The Cutelyst Engine.
Definition: engine.h:33