Cutelyst  2.13.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  Finalized = 0x20,
44  };
45  Q_DECLARE_FLAGS(Status, StatusFlag)
46 
47  explicit EngineRequest();
48 
49  virtual ~EngineRequest();
50 
55  virtual void finalizeBody();
56 
63  virtual void finalizeError();
64 
69  void finalize();
70 
76  virtual void finalizeCookies();
77 
83  virtual bool finalizeHeaders();
84 
88  qint64 write(const char *data, qint64 len);
89 
90  bool webSocketHandshake(const QString &key, const QString &origin, const QString &protocol);
91 
92  virtual bool webSocketSendTextMessage(const QString &message);
93 
94  virtual bool webSocketSendBinaryMessage(const QByteArray &message);
95 
96  virtual bool webSocketSendPing(const QByteArray &payload);
97 
98  virtual bool webSocketClose(quint16 code, const QString &reason);
99 
100 protected:
104  virtual qint64 doWrite(const char *data, qint64 len) = 0;
105 
116  virtual void processingFinished();
117 
121  virtual bool writeHeaders(quint16 status, const Headers &headers) = 0;
122 
123  virtual bool webSocketHandshakeDo(const QString &key, const QString &origin, const QString &protocol);
124 
125 public:
132  void setPath(char *rawPath, const int len);
133 
134  inline void setPath(const QString &path) {
135  QByteArray rawPath = path.toLatin1();
136  setPath(rawPath.data(), rawPath.size());
137  }
138 
140  QString method;
141 
143  QString path;
144 
146  QByteArray query;
147 
149  QString protocol;
150 
153  QString serverAddress;
154 
156  QHostAddress remoteAddress;
157 
159  QString remoteUser;
160 
163 
165  quint64 startOfRequest = 0;
166 
168  Status status = InitialState;
169 
172  QIODevice *body = nullptr;
173 
176  Context *context = nullptr;
177 
179  quint16 remotePort = 0;
180 
182  bool isSecure = false;
183 
185  QElapsedTimer elapsed;
186 };
187 
188 }
189 
190 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
191 
192 #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:51
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