Cutelyst  2.5.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 
210  QJsonDocument bodyJsonDocument() const;
211 
216  QJsonObject bodyJsonObject() const;
217 
222  QJsonArray bodyJsonArray() const;
223 
229  QVariantMap bodyParametersVariant() const;
230 
234  ParamsMultiMap bodyParameters() const;
235 
239  inline QString bodyParameter(const QString &key, const QString &defaultValue = QString()) const;
240 
246  QStringList bodyParameters(const QString &key) const;
247 
251  inline ParamsMultiMap bodyParams() const;
252 
256  inline QString bodyParam(const QString &key, const QString &defaultValue = QString()) const;
257 
263  inline QStringList bodyParams(const QString &key) const;
264 
272  QString queryKeywords() const;
273 
279  QVariantMap queryParametersVariant() const;
280 
284  ParamsMultiMap queryParameters() const;
285 
289  inline QString queryParameter(const QString &key, const QString &defaultValue = QString()) const;
290 
296  QStringList queryParameters(const QString &key) const;
297 
301  inline ParamsMultiMap queryParams() const;
302 
306  inline QString queryParam(const QString &key, const QString &defaultValue = QString()) const;
307 
313  inline QStringList queryParams(const QString &key) const;
314 
318  inline QString contentEncoding() const;
319 
323  inline QString contentType() const;
324 
328  QString cookie(const QString &name) const;
329 
335  QStringList cookies(const QString &name) const;
336 
340  ParamsMultiMap cookies() const;
341 
345  inline QString header(const QString &key) const;
346 
350  Headers headers() const;
351 
355  QString method() const;
356 
360  bool isPost() const;
361 
365  bool isGet() const;
366 
370  bool isHead() const;
371 
375  bool isPut() const;
376 
380  bool isPatch() const;
381 
385  bool isDelete() const;
386 
390  QString protocol() const;
391 
395  inline QString userAgent() const;
396 
400  inline QString referer() const;
401 
405  QString remoteUser() const;
406 
410  QVector<Upload *> uploads() const;
411 
416  QMap<QString, Upload *> uploadsMap() const;
417 
421  Uploads uploads(const QString &name) const;
422 
428  inline Upload *upload(const QString &name) const;
429 
453  ParamsMultiMap mangleParams(const ParamsMultiMap &args, bool append = false) const;
454 
468  QUrl uriWith(const ParamsMultiMap &args, bool append = false) const;
469 
473  Engine *engine() const;
474 
478  Request(EngineRequest *engineRequest);
479 
480 Q_SIGNALS:
485  void webSocketTextFrame(const QString &message, bool isLastFrame, Context *c);
486 
490  void webSocketTextMessage(const QString &message, Context *c);
491 
496  void webSocketBinaryFrame(const QByteArray &message, bool isLastFrame, Context *c);
497 
501  void webSocketBinaryMessage(const QByteArray &message, Context *c);
502 
506  void webSocketPong(const QByteArray &payload, Context *c);
507 
511  void webSocketClosed(quint16 closeCode, const QString &reason);
512 
513 protected:
514  RequestPrivate *d_ptr;
515 
516 private:
517  friend class Application;
518  friend class Dispatcher;
519  friend class DispatchType;
520  friend class Context;
521  Q_DECLARE_PRIVATE(Request)
522 };
523 
524 inline QStringList Request::args() const
525 { return arguments(); }
526 
527 inline QString Request::bodyParameter(const QString &key, const QString &defaultValue) const
528 { return bodyParameters().value(key, defaultValue); }
529 
530 inline ParamsMultiMap Request::bodyParams() const
531 { return bodyParameters(); }
532 
533 inline QString Request::bodyParam(const QString &key, const QString &defaultValue) const
534 { return bodyParameters().value(key, defaultValue); }
535 
536 inline QStringList Request::bodyParams(const QString &key) const
537 { return bodyParameters(key); }
538 
539 inline QString Request::queryParameter(const QString &key, const QString &defaultValue) const
540 { return queryParameters().value(key, defaultValue); }
541 
543 { return queryParameters(); }
544 
545 inline QString Request::queryParam(const QString &key, const QString &defaultValue) const
546 { return queryParameters().value(key, defaultValue); }
547 
548 inline QStringList Request::queryParams(const QString &key) const
549 { return queryParameters(key); }
550 
551 inline QString Request::contentEncoding() const
552 { return headers().contentEncoding(); }
553 
554 inline QString Request::contentType() const
555 { return headers().contentType(); }
556 
557 inline QString Request::header(const QString &key) const
558 { return headers().header(key); }
559 
560 inline QString Request::userAgent() const
561 { return headers().userAgent(); }
562 
563 inline QString Request::referer() const
564 { return headers().referer(); }
565 
566 inline Upload *Request::upload(const QString &name) const
567 { return uploadsMap().value(name); }
568 
569 }
570 
571 #endif // CUTELYST_REQUEST_H
QMap< QString, QString > ParamsMultiMap
QString userAgent() const
QString bodyParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:527
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:533
Upload * upload(const QString &name) const
Definition: request.h:566
QString referer() const
QString queryParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:539
QString header(const QString &key) const
Definition: request.h:557
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:545