Cutelyst  2.3.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 
228  QStringList bodyParameters(const QString &key) const;
229 
233  inline ParamsMultiMap bodyParams() const;
234 
238  inline QString bodyParam(const QString &key, const QString &defaultValue = QString()) const;
239 
245  inline QStringList bodyParams(const QString &key) const;
246 
254  QString queryKeywords() const;
255 
261  QVariantMap queryParametersVariant() const;
262 
266  ParamsMultiMap queryParameters() const;
267 
271  inline QString queryParameter(const QString &key, const QString &defaultValue = QString()) const;
272 
278  QStringList queryParameters(const QString &key) const;
279 
283  inline ParamsMultiMap queryParams() const;
284 
288  inline QString queryParam(const QString &key, const QString &defaultValue = QString()) const;
289 
295  inline QStringList queryParams(const QString &key) const;
296 
300  inline QString contentEncoding() const;
301 
305  inline QString contentType() const;
306 
310  QString cookie(const QString &name) const;
311 
317  QStringList cookies(const QString &name) const;
318 
322  ParamsMultiMap cookies() const;
323 
327  inline QString header(const QString &key) const;
328 
332  Headers headers() const;
333 
337  QString method() const;
338 
342  bool isPost() const;
343 
347  bool isGet() const;
348 
352  QString protocol() const;
353 
357  inline QString userAgent() const;
358 
362  inline QString referer() const;
363 
367  QString remoteUser() const;
368 
372  QVector<Upload *> uploads() const;
373 
378  QMap<QString, Upload *> uploadsMap() const;
379 
383  Uploads uploads(const QString &name) const;
384 
390  inline Upload *upload(const QString &name) const;
391 
415  ParamsMultiMap mangleParams(const ParamsMultiMap &args, bool append = false) const;
416 
430  QUrl uriWith(const ParamsMultiMap &args, bool append = false) const;
431 
435  Engine *engine() const;
436 
440  Request(EngineRequest *engineRequest);
441 
442 Q_SIGNALS:
447  void webSocketTextFrame(const QString &message, bool isLastFrame, Context *c);
448 
452  void webSocketTextMessage(const QString &message, Context *c);
453 
458  void webSocketBinaryFrame(const QByteArray &message, bool isLastFrame, Context *c);
459 
463  void webSocketBinaryMessage(const QByteArray &message, Context *c);
464 
468  void webSocketPong(const QByteArray &payload, Context *c);
469 
473  void webSocketClosed(quint16 closeCode, const QString &reason);
474 
475 protected:
476  RequestPrivate *d_ptr;
477 
478 private:
479  friend class Application;
480  friend class Dispatcher;
481  friend class DispatchType;
482  friend class Context;
483  Q_DECLARE_PRIVATE(Request)
484 };
485 
486 inline QStringList Request::args() const
487 { return arguments(); }
488 
489 inline QString Request::bodyParameter(const QString &key, const QString &defaultValue) const
490 { return bodyParameters().value(key, defaultValue); }
491 
492 inline ParamsMultiMap Request::bodyParams() const
493 { return bodyParameters(); }
494 
495 inline QString Request::bodyParam(const QString &key, const QString &defaultValue) const
496 { return bodyParameters().value(key, defaultValue); }
497 
498 inline QStringList Request::bodyParams(const QString &key) const
499 { return bodyParameters(key); }
500 
501 inline QString Request::queryParameter(const QString &key, const QString &defaultValue) const
502 { return queryParameters().value(key, defaultValue); }
503 
505 { return queryParameters(); }
506 
507 inline QString Request::queryParam(const QString &key, const QString &defaultValue) const
508 { return queryParameters().value(key, defaultValue); }
509 
510 inline QStringList Request::queryParams(const QString &key) const
511 { return queryParameters(key); }
512 
513 inline QString Request::contentEncoding() const
514 { return headers().contentEncoding(); }
515 
516 inline QString Request::contentType() const
517 { return headers().contentType(); }
518 
519 inline QString Request::header(const QString &key) const
520 { return headers().header(key); }
521 
522 inline QString Request::userAgent() const
523 { return headers().userAgent(); }
524 
525 inline QString Request::referer() const
526 { return headers().referer(); }
527 
528 inline Upload *Request::upload(const QString &name) const
529 { return uploadsMap().value(name); }
530 
531 }
532 
533 #endif // CUTELYST_REQUEST_H
QMap< QString, QString > ParamsMultiMap
QString userAgent() const
QString bodyParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:489
QStringList args() const
ParamsMultiMap bodyParams() const
Cutelyst Upload handles file upload request
Definition: upload.h:35
QString contentType() const
ParamsMultiMap queryParams() const
The Cutelyst Context.
Definition: context.h:50
QString bodyParam(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:495
Upload * upload(const QString &name) const
Definition: request.h:528
QString referer() const
QString queryParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:501
QString header(const QString &key) const
Definition: request.h:519
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
QString contentEncoding() 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
QString queryParam(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:507