cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
request.h
1/*
2 * SPDX-FileCopyrightText: (C) 2013-2022 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#ifndef CUTELYST_REQUEST_H
6#define CUTELYST_REQUEST_H
7
8#include <Cutelyst/cutelyst_global.h>
9#include <Cutelyst/headers.h>
10#include <Cutelyst/paramsmultimap.h>
11
12#include <QtCore/qobject.h>
13#include <QtCore/qstringlist.h>
14
15class QIODevice;
16class QHostAddress;
17class QNetworkCookie;
18
19namespace Cutelyst {
20
21class Engine;
22class Upload;
23class Context;
24
30
31class EngineRequest;
32class RequestPrivate;
41class CUTELYST_LIBRARY Request final : public QObject
42{
43 Q_OBJECT
44 Q_PROPERTY(QString hostname READ hostname CONSTANT)
45 Q_PROPERTY(quint16 port READ port CONSTANT)
46 Q_PROPERTY(QUrl uri READ uri CONSTANT)
47 Q_PROPERTY(QString base READ base CONSTANT)
48 Q_PROPERTY(QString path READ path CONSTANT)
49 Q_PROPERTY(QString match READ match CONSTANT)
50 Q_PROPERTY(QStringList arguments READ arguments CONSTANT)
51 Q_PROPERTY(QStringList args READ arguments CONSTANT)
52 Q_PROPERTY(bool secure READ secure CONSTANT)
53 Q_PROPERTY(QVariant bodyData READ bodyData CONSTANT)
54 Q_PROPERTY(Cutelyst::ParamsMultiMap bodyParams READ bodyParameters CONSTANT)
55 Q_PROPERTY(Cutelyst::ParamsMultiMap queryParams READ queryParameters CONSTANT)
56 Q_PROPERTY(QByteArray contentEncoding READ contentEncoding CONSTANT)
57 Q_PROPERTY(QByteArray contentType READ contentType CONSTANT)
58 Q_PROPERTY(QByteArray method READ method CONSTANT)
59 Q_PROPERTY(QByteArray protocol READ protocol CONSTANT)
60 Q_PROPERTY(QByteArray userAgent READ userAgent CONSTANT)
61 Q_PROPERTY(QByteArray referer READ referer CONSTANT)
62 Q_PROPERTY(QString remoteUser READ remoteUser CONSTANT)
63public:
67 virtual ~Request();
68
72 [[nodiscard]] QHostAddress address() const noexcept;
73
83 [[nodiscard]] QString addressString() const;
84
92 [[nodiscard]] QString hostname() const;
93
97 [[nodiscard]] quint16 port() const noexcept;
98
103 [[nodiscard]] QUrl uri() const;
104
114 [[nodiscard]] QString base() const;
115
120 [[nodiscard]] QString path() const noexcept;
121
127 [[nodiscard]] QString match() const noexcept;
128
133 void setMatch(const QString &match);
134
151 [[nodiscard]] QStringList arguments() const noexcept;
152
157 void setArguments(const QStringList &arguments);
158
162 [[nodiscard]] inline QStringList args() const noexcept;
163
167 [[nodiscard]] QStringList captures() const noexcept;
168
173 void setCaptures(const QStringList &captures);
174
182 [[nodiscard]] bool secure() const noexcept;
183
189 [[nodiscard]] QIODevice *body() const noexcept;
190
204 [[nodiscard]] QVariant bodyData() const;
205
210 [[nodiscard]] QCborValue bodyCbor() const;
211
216 [[nodiscard]] QJsonDocument bodyJsonDocument() const;
217
222 [[nodiscard]] QJsonObject bodyJsonObject() const;
223
228 [[nodiscard]] QJsonArray bodyJsonArray() const;
229
235 [[nodiscard]] QVariantMap bodyParametersVariant() const;
236
241 [[nodiscard]] ParamsMultiMap bodyParameters() const;
242
246 [[nodiscard]] inline QString bodyParameter(const QString &key,
247 const QString &defaultValue = {}) const;
248
254 [[nodiscard]] QStringList bodyParameters(const QString &key) const;
255
259 [[nodiscard]] inline ParamsMultiMap bodyParams() const;
260
264 [[nodiscard]] inline QString bodyParam(const QString &key,
265 const QString &defaultValue = {}) const;
266
272 [[nodiscard]] inline QStringList bodyParams(const QString &key) const;
273
281 [[nodiscard]] QString queryKeywords() const;
282
288 [[nodiscard]] QVariantMap queryParametersVariant() const;
289
293 [[nodiscard]] ParamsMultiMap queryParameters() const;
294
299 [[nodiscard]] inline QString queryParameter(const QString &key,
300 const QString &defaultValue = {}) const;
301
307 [[nodiscard]] QStringList queryParameters(const QString &key) const;
308
312 [[nodiscard]] inline ParamsMultiMap queryParams() const;
313
318 [[nodiscard]] inline QString queryParam(const QString &key,
319 const QString &defaultValue = {}) const;
320
326 [[nodiscard]] inline QStringList queryParams(const QString &key) const;
327
331 [[nodiscard]] inline QByteArray contentEncoding() const noexcept;
332
336 [[nodiscard]] inline QByteArray contentType() const;
337
338 struct Cookie {
339 QByteArray name;
340 QByteArray value;
341 };
342
346 [[nodiscard]] QByteArray cookie(QByteArrayView name) const;
347
353 [[nodiscard]] QByteArrayList cookies(QByteArrayView name) const;
354
358 [[nodiscard]] QMultiMap<QByteArrayView, Cookie> cookies() const;
359
363 [[nodiscard]] inline QByteArray header(QByteArrayView key) const noexcept;
364
368 [[nodiscard]] Headers headers() const noexcept;
369
373 [[nodiscard]] QByteArray method() const noexcept;
374
378 [[nodiscard]] bool isPost() const noexcept;
379
383 [[nodiscard]] bool isGet() const noexcept;
384
388 [[nodiscard]] bool isHead() const noexcept;
389
393 [[nodiscard]] bool isPut() const noexcept;
394
398 [[nodiscard]] bool isPatch() const noexcept;
399
403 [[nodiscard]] bool isDelete() const noexcept;
404
408 [[nodiscard]] QByteArray protocol() const noexcept;
409
414 [[nodiscard]] bool xhr() const noexcept;
415
419 [[nodiscard]] inline QByteArray userAgent() const noexcept;
420
424 [[nodiscard]] inline QByteArray referer() const noexcept;
425
429 [[nodiscard]] QString remoteUser() const noexcept;
430
434 [[nodiscard]] QVector<Upload *> uploads() const;
435
440 [[nodiscard]] QMultiMap<QStringView, Upload *> uploadsMap() const;
441
445 [[nodiscard]] Uploads uploads(QStringView name) const;
446
452 [[nodiscard]] inline Upload *upload(QStringView name) const;
453
477 [[nodiscard]] ParamsMultiMap mangleParams(const ParamsMultiMap &args,
478 bool append = false) const;
479
493 [[nodiscard]] QUrl uriWith(const ParamsMultiMap &args, bool append = false) const;
494
498 [[nodiscard]] Engine *engine() const noexcept;
499
503 Request(EngineRequest *engineRequest);
504
505Q_SIGNALS:
510 void webSocketTextFrame(const QString &message, bool isLastFrame, Cutelyst::Context *c);
511
516 void webSocketTextMessage(const QString &message, Cutelyst::Context *c);
517
522 void webSocketBinaryFrame(const QByteArray &message, bool isLastFrame, Cutelyst::Context *c);
523
528 void webSocketBinaryMessage(const QByteArray &message, Cutelyst::Context *c);
529
533 void webSocketPong(const QByteArray &payload, Cutelyst::Context *c);
534
543 void webSocketClosed(quint16 closeCode, const QString &reason);
544
545protected:
546 RequestPrivate *d_ptr;
547
548private:
549 friend class Application;
550 friend class Dispatcher;
551 friend class DispatchType;
552 friend class Context;
553 Q_DECLARE_PRIVATE(Request)
554};
555
556inline QStringList Request::args() const noexcept
557{
558 return arguments();
559}
560
561inline QString Request::bodyParameter(const QString &key, const QString &defaultValue) const
562{
563 return bodyParameters().value(key, defaultValue);
564}
565
566inline ParamsMultiMap Request::bodyParams() const
567{
568 return bodyParameters();
569}
570
571inline QString Request::bodyParam(const QString &key, const QString &defaultValue) const
572{
573 return bodyParameters().value(key, defaultValue);
574}
575
576inline QStringList Request::bodyParams(const QString &key) const
577{
578 return bodyParameters(key);
579}
580
581inline QString Request::queryParameter(const QString &key, const QString &defaultValue) const
582{
583 return queryParameters().value(key, defaultValue);
584}
585
586inline ParamsMultiMap Request::queryParams() const
587{
588 return queryParameters();
589}
590
591inline QString Request::queryParam(const QString &key, const QString &defaultValue) const
592{
593 return queryParameters().value(key, defaultValue);
594}
595
596inline QStringList Request::queryParams(const QString &key) const
597{
598 return queryParameters(key);
599}
600
601inline QByteArray Request::contentEncoding() const noexcept
602{
603 return headers().contentEncoding();
604}
605
606inline QByteArray Request::contentType() const
607{
608 return headers().contentType();
609}
610
611inline QByteArray Request::header(QByteArrayView key) const noexcept
612{
613 return headers().header(key);
614}
615
616inline QByteArray Request::userAgent() const noexcept
617{
618 return headers().userAgent();
619}
620
621inline QByteArray Request::referer() const noexcept
622{
623 return headers().referer();
624}
625
626inline Upload *Request::upload(QStringView name) const
627{
628 return uploadsMap().value(name);
629}
630
631} // namespace Cutelyst
632
633#endif // CUTELYST_REQUEST_H
The Cutelyst application.
Definition application.h:66
The Cutelyst Context.
Definition context.h:42
Abstract class to described a dispatch type.
The Cutelyst Dispatcher.
Definition dispatcher.h:29
The Cutelyst Engine.
Definition engine.h:20
Container for HTTP headers.
Definition headers.h:24
A request.
Definition request.h:42
Cutelyst Upload handles file upload requests.
Definition upload.h:26
QVector< Upload * > Uploads
Definition request.h:29
The Cutelyst namespace holds all public Cutelyst API.
T value(const Key &key, const T &defaultValue) const const