// Copyright (C) 2019 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QHTTPSERVERROUTER_H #define QHTTPSERVERROUTER_H #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE class QAbstractHttpServer; class QHttpServerResponder; class QHttpServerRequest; class QHttpServerRouterRule; class QHttpServerRouterPrivate; class QHttpServerRouter { Q_DECLARE_PRIVATE(QHttpServerRouter) Q_DISABLE_COPY_MOVE(QHttpServerRouter) public: Q_HTTPSERVER_EXPORT QHttpServerRouter(QAbstractHttpServer *server); Q_HTTPSERVER_EXPORT ~QHttpServerRouter(); template bool addConverter(QAnyStringView regexp) { // The QMetaType converter registry is shared by all parts of Qt which uses it. // Only register a converter if it is not already registered. If registering fails, // check that it has been registered by a different thread between the two calls // or return false. The registerConverter function will output an warning if a // converter is already registered. if (!QMetaType::hasRegisteredConverterFunction() && !QMetaType::registerConverter() && !QMetaType::hasRegisteredConverterFunction()) return false; addConverter(QMetaType::fromType(), regexp); return true; } Q_HTTPSERVER_EXPORT void addConverter(QMetaType metaType, QAnyStringView regexp); Q_HTTPSERVER_EXPORT void removeConverter(QMetaType metaType); Q_HTTPSERVER_EXPORT void clearConverters(); Q_HTTPSERVER_EXPORT const QHash &converters() const &; Q_HTTPSERVER_EXPORT QHash converters() &&; template> QHttpServerRouterRule *addRule(std::unique_ptr rule) { return addRuleHelper( std::move(rule), typename ViewTraits::Arguments::Indexes{}); } Q_HTTPSERVER_EXPORT bool handleRequest(const QHttpServerRequest &request, QHttpServerResponder &responder) const; private: template QHttpServerRouterRule *addRuleHelper(std::unique_ptr rule, std::index_sequence) { return addRuleImpl(std::move(rule), {ViewTraits::Arguments::template metaType()...}); } Q_HTTPSERVER_EXPORT QHttpServerRouterRule *addRuleImpl(std::unique_ptr rule, std::initializer_list metaTypes); std::unique_ptr d_ptr; }; QT_END_NAMESPACE #endif // QHTTPSERVERROUTER_H