Function registerHandlerViaRegex

Synopsis

#include <lib/inc/drogon/HttpAppFramework.h>

template <typename FUNCTION>
HttpAppFramework & registerHandlerViaRegex(const std::string &regExp, FUNCTION &&function, const std::vector< internal::HttpConstraint > &filtersAndMethods=std::vector< internal::HttpConstraint >{}, const std::string &handlerName="")

Description

Register a handler into the framework via a regular expression.

Parameters:

regExp - A regular expression string, when the path of a http request matches the regular expression, the handler indicated by the function parameter is called.

Note
When the match is successful, Each string that matches a subexpression is sequentially mapped to a handler parameter.
Parameters:

function - indicates any type of callable object with a valid processing interface.

filtersAndMethods - is the same as the third parameter in the above method.

handlerName - a name for the handler.

Return
HttpAppFramework&

Source

Lines 465-501 in lib/inc/drogon/HttpAppFramework.h.

template <typename FUNCTION>
HttpAppFramework &registerHandlerViaRegex(
    const std::string &regExp,
    FUNCTION &&function,
    const std::vector<internal::HttpConstraint> &filtersAndMethods =
        std::vector<internal::HttpConstraint>{},
    const std::string &handlerName = "")
{
    LOG_TRACE << "regex:" << regExp;
    internal::HttpBinderBasePtr binder;
    binder = std::make_shared<internal::HttpBinder<FUNCTION>>(
        std::forward<FUNCTION>(function));
    std::vector<HttpMethod> validMethods;
    std::vector<std::string> filters;
    for (auto const &filterOrMethod : filtersAndMethods)
    {
        if (filterOrMethod.type() == internal::ConstraintType::HttpFilter)
        {
            filters.push_back(filterOrMethod.getFilterName());
        }
        else if (filterOrMethod.type() ==
                 internal::ConstraintType::HttpMethod)
        {
            validMethods.push_back(filterOrMethod.getHttpMethod());
        }
        else
        {
            LOG_ERROR << "Invalid controller constraint type";
            exit(1);
        }
    }
    registerHttpControllerViaRegex(
        regExp, binder, validMethods, filters, handlerName);
    return *this;
}





Add Discussion as Guest

Log in to DocsForge