Cutelyst  2.1.0
request.h
1 /*
2  * Copyright (C) 2013-2018 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 CUTELYST_REQUEST_H
19 #define CUTELYST_REQUEST_H
20 
21 #include <QtCore/qobject.h>
22 #include <QtCore/qstringlist.h>
23 
24 #include <Cutelyst/cutelyst_global.h>
25 #include <Cutelyst/paramsmultimap.h>
26 #include <Cutelyst/headers.h>
27 
28 class QIODevice;
29 class QHostAddress;
30 
31 namespace Cutelyst {
32 
33 class Engine;
34 class Upload;
35 class Context;
36 
38 typedef QVector<Upload *> Uploads;
39 
40 class EngineRequest;
41 class RequestPrivate;
42 class CUTELYST_LIBRARY Request : public QObject
43 {
44  Q_OBJECT
45  Q_PROPERTY(QString hostname READ hostname CONSTANT)
46  Q_PROPERTY(quint16 port READ port CONSTANT)
47  Q_PROPERTY(QUrl uri READ uri CONSTANT)
48  Q_PROPERTY(QString base READ base CONSTANT)
49  Q_PROPERTY(QString path READ path CONSTANT)
50  Q_PROPERTY(QString match READ match CONSTANT)
51  Q_PROPERTY(QStringList arguments READ arguments CONSTANT)
52  Q_PROPERTY(QStringList args READ arguments CONSTANT)
53  Q_PROPERTY(bool secure READ secure CONSTANT)
54  Q_PROPERTY(QVariant bodyData READ bodyData CONSTANT)
55  Q_PROPERTY(Cutelyst::ParamsMultiMap bodyParams READ bodyParameters CONSTANT)
56  Q_PROPERTY(Cutelyst::ParamsMultiMap queryParams READ queryParameters CONSTANT)
57  Q_PROPERTY(QVariant headers READ headers() CONSTANT)
58  Q_PROPERTY(QString contentEncoding READ contentEncoding CONSTANT)
59  Q_PROPERTY(QString contentType READ contentType CONSTANT)
60  Q_PROPERTY(QString method READ method CONSTANT)
61  Q_PROPERTY(QString protocol READ protocol CONSTANT)
62  Q_PROPERTY(QString userAgent READ userAgent CONSTANT)
63  Q_PROPERTY(QString referer READ referer CONSTANT)
64  Q_PROPERTY(QString remoteUser READ remoteUser CONSTANT)
65 public:
66  virtual ~Request();
67 
71  QHostAddress address() const;
72 
82  QString addressString() const;
83 
91  QString hostname() const;
92 
96  quint16 port() const;
97 
102  QUrl uri() const;
103 
113  QString base() const;
114 
120  QString path() const;
121 
127  QString match() const;
128 
133  void setMatch(const QString &match);
134 
151  QStringList arguments() const;
152 
157  void setArguments(const QStringList &arguments);
158 
162  inline QStringList args() const;
163 
167  QStringList captures() const;
168 
173  void setCaptures(const QStringList &captures);
174 
182  bool secure() const;
183 
189  QIODevice *body() const;
190 
204  QVariant bodyData() const;
205 
211  QVariantMap bodyParametersVariant() const;
212 
216  ParamsMultiMap bodyParameters() const;
217 
221  inline QString bodyParameter(const QString &key, const QString &defaultValue = QString()) const;
222 
226  inline QStringList bodyParameters(const QString &key) const;
227 
231  inline ParamsMultiMap bodyParams() const;
232 
236  inline QString bodyParam(const QString &key, const QString &defaultValue = QString()) const;
237 
241  inline QStringList bodyParams(const QString &key) const;
242 
250  QString queryKeywords() const;
251 
257  QVariantMap queryParametersVariant() const;
258 
262  ParamsMultiMap queryParameters() const;
263 
267  inline QString queryParameter(const QString &key, const QString &defaultValue = QString()) const;
268 
272  inline QStringList queryParameters(const QString &key) const;
273 
277  inline ParamsMultiMap queryParams() const;
278 
282  inline QString queryParam(const QString &key, const QString &defaultValue = QString()) const;
283 
287  inline QStringList queryParams(const QString &key) const;
288 
292  inline QString contentEncoding() const;
293 
297  inline QString contentType() const;
298 
302  QString cookie(const QString &name) const;
303 
307  QMap<QString, QString> cookies() const;
308 
312  inline QString header(const QString &key) const;
313 
317  Headers headers() const;
318 
322  QString method() const;
323 
327  bool isPost() const;
328 
332  bool isGet() const;
333 
337  QString protocol() const;
338 
342  inline QString userAgent() const;
343 
347  inline QString referer() const;
348 
352  QString remoteUser() const;
353 
357  QVector<Upload *> uploads() const;
358 
363  QMap<QString, Upload *> uploadsMap() const;
364 
368  Uploads uploads(const QString &name) const;
369 
375  inline Upload *upload(const QString &name) const;
376 
400  ParamsMultiMap mangleParams(const ParamsMultiMap &args, bool append = false) const;
401 
415  QUrl uriWith(const ParamsMultiMap &args, bool append = false) const;
416 
420  Engine *engine() const;
421 
425  Request(EngineRequest *engineRequest);
426 
427 Q_SIGNALS:
432  void webSocketTextFrame(const QString &message, bool isLastFrame, Context *c);
433 
437  void webSocketTextMessage(const QString &message, Context *c);
438 
443  void webSocketBinaryFrame(const QByteArray &message, bool isLastFrame, Context *c);
444 
448  void webSocketBinaryMessage(const QByteArray &message, Context *c);
449 
453  void webSocketPong(const QByteArray &payload, Context *c);
454 
458  void webSocketClosed(quint16 closeCode, const QString &reason);
459 
460 protected:
461  RequestPrivate *d_ptr;
462 
463 private:
464  friend class Application;
465  friend class Dispatcher;
466  friend class DispatchType;
467  friend class Context;
468  Q_DECLARE_PRIVATE(Request)
469 };
470 
471 inline QStringList Request::args() const
472 { return arguments(); }
473 
474 inline QString Request::bodyParameter(const QString &key, const QString &defaultValue) const
475 { return bodyParameters().value(key, defaultValue); }
476 
477 inline QStringList Request::bodyParameters(const QString &key) const
478 { return bodyParameters().values(key); }
479 
480 inline ParamsMultiMap Request::bodyParams() const
481 { return bodyParameters(); }
482 
483 inline QString Request::bodyParam(const QString &key, const QString &defaultValue) const
484 { return bodyParameters().value(key, defaultValue); }
485 
486 inline QStringList Request::bodyParams(const QString &key) const
487 { return bodyParameters().values(key); }
488 
489 inline QString Request::queryParameter(const QString &key, const QString &defaultValue) const
490 { return queryParameters().value(key, defaultValue); }
491 
492 inline QStringList Request::queryParameters(const QString &key) const
493 { return queryParameters().values(key); }
494 
496 { return queryParameters(); }
497 
498 inline QString Request::queryParam(const QString &key, const QString &defaultValue) const
499 { return queryParameters().value(key, defaultValue); }
500 
501 inline QStringList Request::queryParams(const QString &key) const
502 { return queryParameters().values(key); }
503 
504 inline QString Request::contentEncoding() const
505 { return headers().contentEncoding(); }
506 
507 inline QString Request::contentType() const
508 { return headers().contentType(); }
509 
510 inline QString Request::header(const QString &key) const
511 { return headers().header(key); }
512 
513 inline QString Request::userAgent() const
514 { return headers().userAgent(); }
515 
516 inline QString Request::referer() const
517 { return headers().referer(); }
518 
519 inline Upload *Request::upload(const QString &name) const
520 { return uploadsMap().value(name); }
521 
522 }
523 
524 #endif // CUTELYST_REQUEST_H
QMap< QString, QString > ParamsMultiMap
QString contentType() const
QString contentEncoding() const
QString queryParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:489
ParamsMultiMap bodyParams() const
ParamsMultiMap bodyParameters() const
Definition: request.cpp:214
ParamsMultiMap queryParameters() const
Definition: request.cpp:237
QString queryParam(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:498
Cutelyst Upload handles file upload request
Definition: upload.h:35
QString referer() const
ParamsMultiMap queryParams() const
The Cutelyst Context.
Definition: context.h:50
QString bodyParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:474
Upload * upload(const QString &name) const
Definition: request.h:519
QString bodyParam(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:483
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
QString header(const QString &key) const
Definition: request.h:510
QStringList args() const
QString userAgent() const
The Cutelyst Application.
Definition: application.h:55
QVector< Upload * > Uploads
Definition: request.h:35
The Cutelyst Engine.
Definition: engine.h:33
The Cutelyst Dispatcher.
Definition: dispatcher.h:40