Cutelyst  1.7.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 class Context;
38 
40 typedef QVector<Upload *> Uploads;
41 
42 class RequestPrivate;
43 class CUTELYST_LIBRARY Request : public QObject
44 {
45  Q_OBJECT
46  Q_PROPERTY(QString hostname READ hostname)
47  Q_PROPERTY(quint16 port READ port)
48  Q_PROPERTY(QUrl uri READ uri)
49  Q_PROPERTY(QString base READ base)
50  Q_PROPERTY(QString path READ path)
51  Q_PROPERTY(QString match READ match)
52  Q_PROPERTY(QStringList arguments READ arguments)
53  Q_PROPERTY(QStringList args READ arguments)
54  Q_PROPERTY(bool secure READ secure)
55  Q_PROPERTY(QVariant bodyData READ bodyData)
56  Q_PROPERTY(Cutelyst::ParamsMultiMap bodyParams READ bodyParameters)
57  Q_PROPERTY(Cutelyst::ParamsMultiMap queryParams READ queryParameters)
58  Q_PROPERTY(Cutelyst::ParamsMultiMap parameters READ parameters)
59  Q_PROPERTY(Cutelyst::ParamsMultiMap params READ parameters)
60  Q_PROPERTY(QVariant headers READ headers())
61  Q_PROPERTY(QString contentEncoding READ contentEncoding)
62  Q_PROPERTY(QString contentType READ contentType)
63  Q_PROPERTY(QString method READ method)
64  Q_PROPERTY(QString protocol READ protocol)
65  Q_PROPERTY(QString userAgent READ userAgent)
66  Q_PROPERTY(QString referer READ referer)
67  Q_PROPERTY(QString remoteUser READ remoteUser)
68 public:
69  virtual ~Request();
70 
74  QHostAddress address() const;
75 
85  QString addressString() const;
86 
94  QString hostname() const;
95 
99  quint16 port() const;
100 
105  QUrl uri() const;
106 
116  QString base() const;
117 
123  QString path() const;
124 
130  QString match() const;
131 
136  void setMatch(const QString &match);
137 
154  QStringList arguments() const;
155 
160  void setArguments(const QStringList &arguments);
161 
165  inline QStringList args() const;
166 
170  QStringList captures() const;
171 
176  void setCaptures(const QStringList &captures);
177 
185  bool secure() const;
186 
192  QIODevice *body() const;
193 
207  QVariant bodyData() const;
208 
214  QVariantMap bodyParametersVariant() const;
215 
219  ParamsMultiMap bodyParameters() const;
220 
224  inline QString bodyParameter(const QString &key, const QString &defaultValue = QString()) const;
225 
229  inline QStringList bodyParameters(const QString &key) const;
230 
234  inline ParamsMultiMap bodyParams() const;
235 
239  inline QString bodyParam(const QString &key, const QString &defaultValue = QString()) const;
240 
244  inline QStringList bodyParams(const QString &key) const;
245 
253  QString queryKeywords() const;
254 
260  QVariantMap queryParametersVariant() const;
261 
265  ParamsMultiMap queryParameters() const;
266 
270  inline QString queryParameter(const QString &key, const QString &defaultValue = QString()) const;
271 
275  inline QStringList queryParameters(const QString &key) const;
276 
280  inline ParamsMultiMap queryParams() const;
281 
285  inline QString queryParam(const QString &key, const QString &defaultValue = QString()) const;
286 
290  inline QStringList queryParams(const QString &key) const;
291 
297  QVariantMap parametersVariant() const;
298 
303  ParamsMultiMap parameters() const;
304 
309  inline QString param(const QString &key, const QString &defaultValue = QString()) const;
310 
315  inline QStringList params(const QString &key) const;
316 
320  inline ParamsMultiMap params() const;
321 
325  inline QString contentEncoding() const;
326 
330  inline QString contentType() const;
331 
335  QString cookie(const QString &name) const;
336 
340  QMap<QString, QString> 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  QString protocol() const;
371 
375  inline QString userAgent() const;
376 
380  inline QString referer() const;
381 
385  QString remoteUser() const;
386 
390  QVector<Upload *> uploads() const;
391 
396  QMap<QString, Upload *> uploadsMap() const;
397 
401  Uploads uploads(const QString &name) const;
402 
408  inline Upload *upload(const QString &name) const;
409 
433  ParamsMultiMap mangleParams(const ParamsMultiMap &args, bool append = false) const;
434 
448  QUrl uriWith(const ParamsMultiMap &args, bool append = false) const;
449 
453  Engine *engine() const;
454 
459  void *engineData();
460 
464  Request(RequestPrivate *prv);
465 
466 Q_SIGNALS:
471  void webSocketTextFrame(const QString &message, bool isLastFrame, Context *c);
472 
476  void webSocketTextMessage(const QString &message, Context *c);
477 
482  void webSocketBinaryFrame(const QByteArray &message, bool isLastFrame, Context *c);
483 
487  void webSocketBinaryMessage(const QByteArray &message, Context *c);
488 
492  void webSocketPong(const QByteArray &payload, Context *c);
493 
497  void webSocketClosed(quint16 closeCode, const QString &reason);
498 
499 protected:
500  RequestPrivate *d_ptr;
501 
502 private:
503  friend class Application;
504  friend class Dispatcher;
505  friend class DispatchType;
506  Q_DECLARE_PRIVATE(Request)
507 };
508 
509 inline QStringList Request::args() const
510 { return arguments(); }
511 
512 inline QString Request::bodyParameter(const QString &key, const QString &defaultValue) const
513 { return bodyParameters().value(key, defaultValue); }
514 
515 inline QStringList Request::bodyParameters(const QString &key) const
516 { return bodyParameters().values(key); }
517 
518 inline ParamsMultiMap Request::bodyParams() const
519 { return bodyParameters(); }
520 
521 inline QString Request::bodyParam(const QString &key, const QString &defaultValue) const
522 { return bodyParameters().value(key, defaultValue); }
523 
524 inline QStringList Request::bodyParams(const QString &key) const
525 { return bodyParameters().values(key); }
526 
527 inline QString Request::queryParameter(const QString &key, const QString &defaultValue) const
528 { return queryParameters().value(key, defaultValue); }
529 
530 inline QStringList Request::queryParameters(const QString &key) const
531 { return queryParameters().values(key); }
532 
534 { return queryParameters(); }
535 
536 inline QString Request::queryParam(const QString &key, const QString &defaultValue) const
537 { return queryParameters().value(key, defaultValue); }
538 
539 inline QStringList Request::queryParams(const QString &key) const
540 { return queryParameters().values(key); }
541 
542 inline QString Request::param(const QString &key, const QString &defaultValue) const
543 { return parameters().value(key, defaultValue); }
544 
545 inline QStringList Request::params(const QString &key) const
546 { return parameters().values(key); }
547 
548 inline ParamsMultiMap Request::params() const
549 { return parameters(); }
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 contentType() const
QString contentEncoding() const
QString queryParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:527
ParamsMultiMap bodyParameters() const
ParamsMultiMap params() const
ParamsMultiMap bodyParams() const
QString queryParam(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:536
Cutelyst Upload handles file upload request
Definition: upload.h:37
QString referer() const
ParamsMultiMap queryParams() const
The Cutelyst Context.
Definition: context.h:52
QString bodyParameter(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:512
ParamsMultiMap queryParameters() const
Upload * upload(const QString &name) const
Definition: request.h:566
QString bodyParam(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:521
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
QString header(const QString &key) const
Definition: request.h:557
QStringList args() const
QString userAgent() const
The Cutelyst Application.
Definition: application.h:56
QVector< Upload * > Uploads
Definition: request.h:37
QString param(const QString &key, const QString &defaultValue=QString()) const
Definition: request.h:542
The Cutelyst Dispatcher.
Definition: dispatcher.h:41