Cutelyst  2.3.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 
24 #include <Cutelyst/Headers>
25 
26 namespace Cutelyst {
27 
28 class Engine;
29 class Context;
30 class CUTELYST_LIBRARY EngineRequest
31 {
32  Q_GADGET
33  friend class Engine;
34 public:
35  enum StatusFlag {
36  InitialState = 0x00,
37  FinalizedHeaders = 0x01,
38  IOWrite = 0x02,
39  Chunked = 0x04,
40  ChunkedDone = 0x08,
41  };
42  Q_DECLARE_FLAGS(Status, StatusFlag)
43 
44  explicit EngineRequest();
45 
46  virtual ~EngineRequest();
47 
52  virtual void finalizeBody();
53 
60  virtual void finalizeError();
61 
66  void finalize();
67 
73  virtual void finalizeCookies();
74 
80  virtual bool finalizeHeaders();
81 
85  qint64 write(const char *data, qint64 len);
86 
87  bool webSocketHandshake(const QString &key, const QString &origin, const QString &protocol);
88 
89  virtual bool webSocketSendTextMessage(const QString &message);
90 
91  virtual bool webSocketSendBinaryMessage(const QByteArray &message);
92 
93  virtual bool webSocketSendPing(const QByteArray &payload);
94 
95  virtual bool webSocketClose(quint16 code, const QString &reason);
96 
97 protected:
101  virtual qint64 doWrite(const char *data, qint64 len) = 0;
102 
113  virtual void processingFinished();
114 
118  virtual bool writeHeaders(quint16 status, const Headers &headers) = 0;
119 
120  virtual bool webSocketHandshakeDo(const QString &key, const QString &origin, const QString &protocol);
121 
122 public:
124  QString method;
125 
127  QString path;
128 
130  QByteArray query;
131 
133  QString protocol;
134 
137  QString serverAddress;
138 
140  QHostAddress remoteAddress;
141 
143  QString remoteUser;
144 
147 
149  quint64 startOfRequest;
150 
152  Status status = InitialState;
153 
156  QIODevice *body = nullptr;
157 
160  Context *context = nullptr;
161 
163  quint16 remotePort = 0;
164 
166  bool isSecure = false;
167 };
168 
169 }
170 
171 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
172 
173 #endif // ENGINEREQUEST_H
QString path
The path requested by the user agent &#39;/index&#39;, MUST NOT have a leading slash.
QString protocol
The protocol requested by the user agent &#39;HTTP1/1&#39;.
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 &#39;Host&#39; header but if that&#39;s not pres...
quint64 startOfRequest
The timestamp of the start of headers.
QByteArray query
The query string requested by the user agent &#39;foo=bar&baz&#39;.
The Cutelyst Engine.
Definition: engine.h:33