1 | // Copyright (C) 2019 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QHTTPSERVERROUTERRULE_H |
5 | #define QHTTPSERVERROUTERRULE_H |
6 | |
7 | #include <QtHttpServer/qhttpserverrequest.h> |
8 | |
9 | #include <QtCore/qcontainerfwd.h> |
10 | |
11 | #include <functional> // for std::function |
12 | #include <initializer_list> |
13 | #include <memory> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class QString; |
18 | class QHttpServerRequest; |
19 | class QHttpServerResponder; |
20 | class QRegularExpressionMatch; |
21 | class QHttpServerRouter; |
22 | |
23 | class QHttpServerRouterRulePrivate; |
24 | class Q_HTTPSERVER_EXPORT QHttpServerRouterRule |
25 | { |
26 | Q_DECLARE_PRIVATE(QHttpServerRouterRule) |
27 | Q_DISABLE_COPY_MOVE(QHttpServerRouterRule) |
28 | |
29 | public: |
30 | using RouterHandler = std::function<void(const QRegularExpressionMatch &, |
31 | const QHttpServerRequest &, QHttpServerResponder &&)>; |
32 | |
33 | explicit QHttpServerRouterRule(const QString &pathPattern, RouterHandler routerHandler); |
34 | explicit QHttpServerRouterRule(const QString &pathPattern, |
35 | const QHttpServerRequest::Methods methods, |
36 | RouterHandler routerHandler); |
37 | virtual ~QHttpServerRouterRule(); |
38 | |
39 | protected: |
40 | bool exec(const QHttpServerRequest &request, QHttpServerResponder &responder) const; |
41 | |
42 | bool hasValidMethods() const; |
43 | |
44 | bool createPathRegexp(std::initializer_list<QMetaType> metaTypes, |
45 | const QHash<QMetaType, QString> &converters); |
46 | |
47 | virtual bool matches(const QHttpServerRequest &request, |
48 | QRegularExpressionMatch *match) const; |
49 | |
50 | QHttpServerRouterRule(QHttpServerRouterRulePrivate *d); |
51 | |
52 | private: |
53 | std::unique_ptr<QHttpServerRouterRulePrivate> d_ptr; |
54 | |
55 | friend class QHttpServerRouter; |
56 | }; |
57 | |
58 | QT_END_NAMESPACE |
59 | |
60 | #endif // QHTTPSERVERROUTERRULE_H |
61 |