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
QIODevice
Cutelyst::Context
The Cutelyst Context.
Definition: context.h:52
QString::toLatin1
QByteArray toLatin1() const const
Cutelyst::EngineRequest::method
QString method
The method used (GET, POST...)
Definition: enginerequest.h:148
Cutelyst::EngineRequest::headers
Headers headers
The request headers.
Definition: enginerequest.h:170
Cutelyst::EngineRequest
Definition: enginerequest.h:40
QString
Cutelyst::EngineRequest::path
QString path
Call setPath() instead.
Definition: enginerequest.h:151
Cutelyst::EngineRequest::protocol
QString protocol
The protocol requested by the user agent 'HTTP1/1'.
Definition: enginerequest.h:157
Cutelyst::Headers
Definition: headers.h:30
Cutelyst::EngineRequest::writeHeaders
virtual bool writeHeaders(quint16 status, const Headers &headers)=0
Reimplement this to write the headers back to the client.
QElapsedTimer
Cutelyst::EngineRequest::elapsed
QElapsedTimer elapsed
The elapsed timer since the start of request.
Definition: enginerequest.h:193
QHostAddress
Cutelyst::EngineRequest::serverAddress
QString serverAddress
The server address which the server is listening to, usually the 'Host' header but if that's not pres...
Definition: enginerequest.h:161
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8
Cutelyst::EngineRequest::remoteAddress
QHostAddress remoteAddress
The remote/client address.
Definition: enginerequest.h:164
Cutelyst::Engine
The Cutelyst Engine.
Definition: engine.h:34
QByteArray::size
int size() const const
Cutelyst::EngineRequest::doWrite
virtual qint64 doWrite(const char *data, qint64 len)=0
Reimplement this to do the RAW writing to the client.
Cutelyst::EngineRequest::query
QByteArray query
The query string requested by the user agent 'foo=bar&baz'.
Definition: enginerequest.h:154
Cutelyst::EngineRequest::remoteUser
QString remoteUser
The remote user name set by a front web server.
Definition: enginerequest.h:167
QByteArray::data
char * data()
QByteArray