Cutelyst  1.11.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 public:
34  enum StatusFlag {
35  InitialState = 0x00,
36  FinalizedHeaders = 0x01,
37  IOWrite = 0x02,
38  Chunked = 0x04,
39  ChunkedDone = 0x08,
40  };
41  Q_DECLARE_FLAGS(Status, StatusFlag)
42 
43  explicit EngineRequest(Engine *_engine);
44 
45  virtual ~EngineRequest();
46 
51  virtual void finalizeBody(Context *c);
52 
59  virtual void finalizeError(Context *c);
60 
65  void finalize(Context *c);
66 
72  virtual void finalizeCookies(Context *c);
73 
79  virtual bool finalizeHeaders(Context *c);
80 
84  qint64 write(const char *data, qint64 len);
85 
86  bool webSocketHandshake(Context *c, const QString &key, const QString &origin, const QString &protocol);
87 
88  virtual bool webSocketSendTextMessage(const QString &message);
89 
90  virtual bool webSocketSendBinaryMessage(const QByteArray &message);
91 
92  virtual bool webSocketSendPing(const QByteArray &payload);
93 
94  virtual bool webSocketClose(quint16 code, const QString &reason);
95 
96 protected:
100  virtual qint64 doWrite(const char *data, qint64 len) = 0;
101 
105  virtual bool writeHeaders(quint16 status, const Headers &headers) = 0;
106 
107  virtual bool webSocketHandshakeDo(Context *c, const QString &key, const QString &origin, const QString &protocol);
108 
109 public:
111  QString method;
112 
114  QString path;
115 
117  QByteArray query;
118 
120  QString protocol;
121 
124  QString serverAddress;
125 
127  QHostAddress remoteAddress;
128 
130  QString remoteUser;
131 
134 
136  quint64 startOfRequest;
137 
139  QIODevice *body = nullptr;
140 
142  void *requestPtr;// TODO remove on CUTELYST2
143 
145  quint16 remotePort = 0;
146 
148  bool isSecure = false;
149 
151  Engine *engine;// TODO REORDER on CUTELYST2
152 
154  Status status = InitialState;// TODO REORDER on CUTELYST2
155 };
156 
157 }
158 
159 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::EngineRequest::Status)
160 
161 #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
void * requestPtr
The internal pointer of the request, to be used for mapping this request to the real request...
Engine * engine
Pointer to parent Engine class.
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