Cutelyst  2.14.2
enginerequest.h
Go to the documentation of this file.
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 
26 #ifndef ENGINEREQUEST_H
27 #define ENGINEREQUEST_H
28 
29 #include <QObject>
30 #include <QHostAddress>
31 #include <QElapsedTimer>
32 
33 #include <Cutelyst/Headers>
34 
35 namespace Cutelyst {
36 
37 class Engine;
38 class Context;
39 class CUTELYST_LIBRARY EngineRequest
40 {
41  Q_GADGET
42  friend class Engine;
43 public:
44  enum StatusFlag {
45  InitialState = 0x00,
46  FinalizedHeaders = 0x01,
47  IOWrite = 0x02,
48  Chunked = 0x04,
49  ChunkedDone = 0x08,
50  Async = 0x10,
51  Finalized = 0x20,
52  };
53  Q_DECLARE_FLAGS(Status, StatusFlag)
54 
55  explicit EngineRequest();
56 
57  virtual ~EngineRequest();
58 
63  virtual void finalizeBody();
64 
71  virtual void finalizeError();
72 
77  void finalize();
78 
84  virtual void finalizeCookies();
85 
91  virtual bool finalizeHeaders();
92 
96  qint64 write(const char *data, qint64 len);
97 
98  bool webSocketHandshake(const QString &key, const QString &origin, const QString &protocol);
99 
100  virtual bool webSocketSendTextMessage(const QString &message);
101 
102  virtual bool webSocketSendBinaryMessage(const QByteArray &message);
103 
104  virtual bool webSocketSendPing(const QByteArray &payload);
105 
106  virtual bool webSocketClose(quint16 code, const QString &reason);
107 
108 protected:
112  virtual qint64 doWrite(const char *data, qint64 len) = 0;
113 
124  virtual void processingFinished();
125 
129  virtual bool writeHeaders(quint16 status, const Headers &headers) = 0;
130 
131  virtual bool webSocketHandshakeDo(const QString &key, const QString &origin, const QString &protocol);
132 
133 public:
140  void setPath(char *rawPath, const int len);
141 
142  inline void setPath(const QString &path) {
143  QByteArray rawPath = path.toLatin1();
144  setPath(rawPath.data(), rawPath.size());
145  }
146 
149 
152 
155 
158 
162 
165 
168 
171 
173  quint64 startOfRequest = 0;
174 
176  Status status = InitialState;
177 
180  QIODevice *body = nullptr;
181 
184  Context *context = nullptr;
185 
187  quint16 remotePort = 0;
188 
190  bool isSecure = false;
191 
194 };
195 
196 }
197 
198 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
199 
200 #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.
QString method
The method used (GET, POST...)
QByteArray toLatin1() const
char * data()
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'.
int size() const
The Cutelyst Engine.
Definition: engine.h:33