Cutelyst  1.5.0
request.h
1 /*
2  * Copyright (C) 2013-2016 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 Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef CUTELYST_REQUEST_H
21 #define CUTELYST_REQUEST_H
22 
23 #include <QtCore/qobject.h>
24 #include <QtCore/qstringlist.h>
25 
26 #include <Cutelyst/cutelyst_global.h>
27 #include <Cutelyst/paramsmultimap.h>
28 #include <Cutelyst/headers.h>
29 
30 class QIODevice;
31 class QHostAddress;
32 
33 namespace Cutelyst {
34 
35 class Engine;
36 class Upload;
37 
38 typedef QVector<Upload *> Uploads;
39 
40 class RequestPrivate;
41 class CUTELYST_LIBRARY Request : public QObject
42 {
43  Q_OBJECT
44  Q_PROPERTY(QString hostname READ hostname)
45  Q_PROPERTY(quint16 port READ port)
46  Q_PROPERTY(QUrl uri READ uri)
47  Q_PROPERTY(QString base READ base)
48  Q_PROPERTY(QString path READ path)
49  Q_PROPERTY(QString match READ match)
50  Q_PROPERTY(QStringList arguments READ arguments)
51  Q_PROPERTY(QStringList args READ arguments)
52  Q_PROPERTY(bool secure READ secure)
53  Q_PROPERTY(QVariant bodyData READ bodyData)
54  Q_PROPERTY(Cutelyst::ParamsMultiMap bodyParams READ bodyParameters)
55  Q_PROPERTY(Cutelyst::ParamsMultiMap queryParams READ queryParameters)
56  Q_PROPERTY(Cutelyst::ParamsMultiMap parameters READ parameters)
57  Q_PROPERTY(Cutelyst::ParamsMultiMap params READ parameters)
58  Q_PROPERTY(QVariant headers READ headers())
59  Q_PROPERTY(QString contentEncoding READ contentEncoding)
60  Q_PROPERTY(QString contentType READ contentType)
61  Q_PROPERTY(QString method READ method)
62  Q_PROPERTY(QString protocol READ protocol)
63  Q_PROPERTY(QString userAgent READ userAgent)
64  Q_PROPERTY(QString referer READ referer)
65  Q_PROPERTY(QString remoteUser READ remoteUser)
66 public:
67  virtual ~Request();
68 
72  QHostAddress address() const;
73 
83  QString addressString() const;
84 
92  QString hostname() const;
93 
97  quint16 port() const;
98 
103  QUrl uri() const;
104 
114  QString base() const;
115 
121  QString path() const;
122 
128  QString match() const;
129 
134  void setMatch(const QString &match);
135 
152  QStringList arguments() const;
153 
158  void setArguments(const QStringList &arguments);
159 
163  inline QStringList args() const;
164 
168  QStringList captures() const;
169 
174  void setCaptures(const QStringList &captures);
175 
183  bool secure() const;
184 
190  QIODevice *body() const;
191 
205  QVariant bodyData() const;
206 
207  QVariantMap bodyParametersVariant() const;
208 
212  ParamsMultiMap bodyParameters() const;
213 
217  inline QString bodyParameter(const QString &key, const QString &defaultValue = QString()) const;
218 
222  inline QStringList bodyParameters(const QString &key) const;
223 
227  inline ParamsMultiMap bodyParams() const;
228 
232  inline QString bodyParam(const QString &key, const QString &defaultValue = QString()) const;
233 
237  inline QStringList bodyParams(const QString &key) const;
238 
246  QString queryKeywords() const;
247 
248 
249  QVariantMap queryParametersVariant() const;
250 
254  ParamsMultiMap queryParameters() const;
255 
259  inline QString queryParameter(const QString &key, const QString &defaultValue = QString()) const;
260 
264  inline QStringList queryParameters(const QString &key) const;
265 
269  inline ParamsMultiMap queryParams() const;
270 
274  inline QString queryParam(const QString &key, const QString &defaultValue = QString()) const;
275 
279  inline QStringList queryParams(const QString &key) const;
280 
281  QVariantMap parametersVariant() const;
282 
287  ParamsMultiMap parameters() const;
288 
293  inline QString param(const QString &key, const QString &defaultValue = QString()) const;
294 
299  inline QStringList params(const QString &key) const;
300 
304  inline ParamsMultiMap params() const;
305 
309  inline QString contentEncoding() const;
310 
314  inline QString contentType() const;
315 
319  QString cookie(const QString &name) const;
320 
324  QMap<QString, QString> cookies() const;
325 
329  inline QString header(const QString &key) const;
330 
334  Headers headers() const;
335 
339  QString method() const;
340 
344  bool isPost() const;
345 
349  bool isGet() const;
350 
354  QString protocol() const;
355 
359  inline QString userAgent() const;
360 
364  inline QString referer() const;
365 
369  QString remoteUser() const;
370 
374  QVector<Upload *> uploads() const;
375 
380  QMap<QString, Upload *> uploadsMap() const;
381 
385  Uploads uploads(const QString &name) const;
386 
392  inline Upload *upload(const QString &name) const;
393 
417  ParamsMultiMap mangleParams(const ParamsMultiMap &args, bool append = false) const;
418 
432  QUrl uriWith(const ParamsMultiMap &args, bool append = false) const;
433 
437  Engine *engine() const;
438 
443  void *engineData();
444 
445  Request(RequestPrivate *prv);
446 
447 protected:
448  RequestPrivate *d_ptr;
449 
450 private:
451  friend class Application;
452  friend class Dispatcher;
453  friend class DispatchType;
454  Q_DECLARE_PRIVATE(Request)
455 };
456 
457 inline QStringList Request::args() const
458 { return arguments(); }
459 
460 inline QString Request::bodyParameter(const QString &key, const QString &defaultValue) const
461 { return bodyParameters().value(key, defaultValue); }
462 
463 inline QStringList Request::bodyParameters(const QString &key) const
464 { return bodyParameters().values(key); }
465 
466 inline ParamsMultiMap Request::bodyParams() const
467 { return bodyParameters(); }
468 
469 inline QString Request::bodyParam(const QString &key, const QString &defaultValue) const
470 { return bodyParameters().value(key, defaultValue); }
471 
472 inline QStringList Request::bodyParams(const QString &key) const
473 { return bodyParameters().values(key); }
474 
475 inline QString Request::queryParameter(const QString &key, const QString &defaultValue) const
476 { return queryParameters().value(key, defaultValue); }
477 
478 inline QStringList Request::queryParameters(const QString &key) const
479 { return queryParameters().values(key); }
480 
482 { return queryParameters(); }
483 
484 inline QString Request::queryParam(const QString &key, const QString &defaultValue) const
485 { return queryParameters().value(key, defaultValue); }
486 
487 inline QStringList Request::queryParams(const QString &key) const
488 { return queryParameters().values(key); }
489 
490 inline QString Request::param(const QString &key, const QString &defaultValue) const
491 { return parameters().value(key, defaultValue); }
492 
493 inline QStringList Request::params(const QString &key) const
494 { return parameters().values(key); }
495 
496 inline ParamsMultiMap Request::params() const
497 { return parameters(); }
498 
499 inline QString Request::contentEncoding() const
500 { return headers().contentEncoding(); }
501 
502 inline QString Request::contentType() const
503 { return headers().contentType(); }
504 
505 inline QString Request::header(const QString &key) const
506 { return headers().header(key); }
507 
508 inline QString Request::userAgent() const
509 { return headers().userAgent(); }
510 
511 inline QString Request::referer() const
512 { return headers().referer(); }
513 
514 inline Upload *Request::upload(const QString &name) const
515 { return uploadsMap().value(name); }
516 
517 }
518 
519 #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:475
ParamsMultiMap bodyParameters() const
ParamsMultiMap params() const
ParamsMultiMap bodyParams() const
QString queryParam(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:484
QString referer() const
ParamsMultiMap queryParams() const
QString bodyParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:460
ParamsMultiMap queryParameters() const
Upload * upload(const QString &name) const
Definition: request.h:514
QString bodyParam(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:469
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
QString header(const QString &key) const
Definition: request.h:505
QStringList args() const
QString userAgent() const
The Cutelyst Application.
Definition: application.h:55
QString param(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:490
The Cutelyst Dispatcher.
Definition: dispatcher.h:41