Loading...
Searching...
No Matches
express.hpp
Go to the documentation of this file.
/*
restinio
*/
#pragma once
#include <restinio/router/impl/target_path_holder.hpp>
#include <restinio/router/non_matched_request_handler.hpp>
#include <restinio/optional.hpp>
#include <restinio/path2regex/path2regex.hpp>
#include <restinio/router/std_regex_engine.hpp>
#include <restinio/router/method_matcher.hpp>
#include <restinio/utils/from_string.hpp>
#include <restinio/utils/percent_encoding.hpp>
#include <map>
#include <vector>
namespace restinio
{
namespace router
{
namespace impl
{
struct route_params_accessor_t;
} /* namespace impl */
//
// route_params_t
//
class route_params_t final
{
public:
using named_parameters_container_t =
std::vector< std::pair< string_view_t, string_view_t > >;
using indexed_parameters_container_t =
std::vector< string_view_t >;
private:
friend struct impl::route_params_accessor_t;
void
match(
std::unique_ptr< char[] > request_target,
std::shared_ptr< std::string > key_names_buffer,
string_view_t match,
named_parameters_container_t named_parameters,
indexed_parameters_container_t indexed_parameters )
{
m_request_target = std::move( request_target );
m_key_names_buffer = std::move( key_names_buffer );
m_match = match;
m_named_parameters = std::move( named_parameters );
m_indexed_parameters = std::move( indexed_parameters );
}
public:
route_params_t() = default;
route_params_t( route_params_t && ) = default;
route_params_t & operator = ( route_params_t && ) = default;
route_params_t( const route_params_t & ) = delete;
route_params_t & operator = ( const route_params_t & ) = delete;
string_view_t match() const noexcept { return m_match; }
string_view_t
operator [] ( string_view_t key ) const
{
return find_named_parameter_with_check( key ).second;
}
bool
has( string_view_t key ) const noexcept
{
return m_named_parameters.end() != find_named_parameter( key );
}
optional_t< string_view_t >
get_param( string_view_t key ) const noexcept
{
const auto it = find_named_parameter( key );
return m_named_parameters.end() != it ?
optional_t< string_view_t >{ it->second } :
optional_t< string_view_t >{ nullopt };
}
string_view_t
operator [] ( std::size_t i ) const
{
if( i >= m_indexed_parameters.size() )
throw exception_t{
fmt::format(
RESTINIO_FMT_FORMAT_STRING( "invalid parameter index: {}" ),
i )
};
return m_indexed_parameters.at( i );
}
auto named_parameters_size() const noexcept { return m_named_parameters.size(); }
auto indexed_parameters_size() const noexcept { return m_indexed_parameters.size(); }
private:
named_parameters_container_t::const_iterator
find_named_parameter( string_view_t key ) const noexcept
{
return
std::find_if(
m_named_parameters.begin(),
m_named_parameters.end(),
[&]( const auto p ){
return key == p.first;
} );
}
named_parameters_container_t::const_reference
find_named_parameter_with_check( string_view_t key ) const
{
auto it = find_named_parameter( key );
if( m_named_parameters.end() == it )
throw exception_t{
fmt::format(
RESTINIO_FMT_FORMAT_STRING( "invalid parameter name: {}" ),
std::string{ key.data(), key.size() } ) };
return *it;
}
std::unique_ptr< char[] > m_request_target;
std::shared_ptr< std::string > m_key_names_buffer;
string_view_t m_match;
named_parameters_container_t m_named_parameters;
indexed_parameters_container_t m_indexed_parameters;
};
namespace impl
{
//
// route_params_accessor_t
//
struct route_params_accessor_t
{
static void
match(
route_params_t & rp,
std::unique_ptr< char[] > request_target,
std::shared_ptr< std::string > key_names_buffer,
string_view_t match_,
route_params_t::named_parameters_container_t named_parameters,
route_params_t::indexed_parameters_container_t indexed_parameters )
{
rp.match(
std::move( request_target ),
std::move( key_names_buffer ),
match_,
std::move( named_parameters ),
std::move( indexed_parameters ) );
}
static const auto &
named_parameters( const route_params_t & rp ) noexcept
{
return rp.m_named_parameters;
}
static const auto &
indexed_parameters( const route_params_t & rp ) noexcept
{
return rp.m_indexed_parameters;
}
};
//
// route_params_appender_t
//
class route_params_appender_t
{
public:
route_params_appender_t(
route_params_t::named_parameters_container_t & named_parameters,
route_params_t::indexed_parameters_container_t & indexed_parameters )
: m_named_parameters{ named_parameters }
, m_indexed_parameters{ indexed_parameters }
{}
route_params_appender_t( const route_params_appender_t & ) = delete;
route_params_appender_t( route_params_appender_t && ) = delete;
route_params_appender_t & operator = ( const route_params_appender_t & ) = delete;
route_params_appender_t & operator = ( route_params_appender_t && ) = delete;
void
add_named_param( string_view_t key, string_view_t value )
{
m_named_parameters.emplace_back( key, value );
}
void
add_indexed_param( string_view_t value )
{
m_indexed_parameters.emplace_back( value );
}
private:
route_params_t::named_parameters_container_t & m_named_parameters;
route_params_t::indexed_parameters_container_t & m_indexed_parameters;
};
using param_appender_sequence_t =
path2regex::param_appender_sequence_t< route_params_appender_t >;
//
// route_matcher_t
//
template < typename Regex_Engine = std_regex_engine_t >
class route_matcher_t
{
public:
using regex_t = typename Regex_Engine::compiled_regex_t;
using match_results_t = typename Regex_Engine::match_results_t;
route_matcher_t(
http_method_id_t method,
regex_t route_regex,
std::shared_ptr< std::string > named_params_buffer,
param_appender_sequence_t param_appender_sequence )
: m_route_regex{ std::move( route_regex ) }
, m_named_params_buffer{ std::move( named_params_buffer ) }
, m_param_appender_sequence{ std::move( param_appender_sequence ) }
{
assign( m_method_matcher, std::move(method) );
}
template< typename Method_Matcher >
route_matcher_t(
Method_Matcher && method_matcher,
regex_t route_regex,
std::shared_ptr< std::string > named_params_buffer,
param_appender_sequence_t param_appender_sequence )
: m_route_regex{ std::move( route_regex ) }
, m_named_params_buffer{ std::move( named_params_buffer ) }
, m_param_appender_sequence{ std::move( param_appender_sequence ) }
{
assign(
m_method_matcher,
std::forward<Method_Matcher>(method_matcher) );
}
route_matcher_t() = default;
route_matcher_t( route_matcher_t && ) = default;
bool
match_route(
target_path_holder_t & target_path,
route_params_t & parameters ) const
{
match_results_t matches;
if( Regex_Engine::try_match(
target_path.view(),
m_route_regex,
matches ) )
{
assert( m_param_appender_sequence.size() + 1 >= matches.size() );
// Data for route_params_t initialization.
auto captured_params = target_path.giveout_data();
const string_view_t match{
captured_params.get() + Regex_Engine::submatch_begin_pos( matches[0] ),
Regex_Engine::submatch_end_pos( matches[0] ) -
Regex_Engine::submatch_begin_pos( matches[0] ) } ;
route_params_t::named_parameters_container_t named_parameters;
route_params_t::indexed_parameters_container_t indexed_parameters;
route_params_appender_t param_appender{ named_parameters, indexed_parameters };
// Std regex and pcre engines handle
// trailing groups with empty values differently.
// Std despite they are empty includes them in the list of match results;
// Pcre on the other hand does not.
// So the second for is for pushing empty values
std::size_t i = 1;
for( ; i < matches.size(); ++i )
{
const auto & m = matches[ i ];
m_param_appender_sequence[ i - 1](
param_appender,
string_view_t{
captured_params.get() + Regex_Engine::submatch_begin_pos( m ),
Regex_Engine::submatch_end_pos( m ) -
Regex_Engine::submatch_begin_pos( m ) } );
}
for( ; i < m_param_appender_sequence.size() + 1; ++i )
{
m_param_appender_sequence[ i - 1 ](
param_appender,
string_view_t{ captured_params.get(), 0 } );
}
// Init route parameters.
route_params_accessor_t::match(
parameters,
std::move( captured_params ),
m_named_params_buffer, // Do not move (it is used on each match).
std::move( match ),
std::move( named_parameters ),
std::move( indexed_parameters ) );
return true;
}
return false;
}
inline bool
operator () (
const http_request_header_t & h,
target_path_holder_t & target_path,
route_params_t & parameters ) const
{
return m_method_matcher->match( h.method() ) &&
match_route( target_path, parameters );
}
private:
buffered_matcher_holder_t m_method_matcher;
regex_t m_route_regex;
std::shared_ptr< std::string > m_named_params_buffer;
param_appender_sequence_t m_param_appender_sequence;
};
} /* namespace impl */
//
// generic_express_request_handler_t
//
template< typename Extra_Data >
using generic_express_request_handler_t = std::function<
request_handling_status_t(
generic_request_handle_t<Extra_Data>,
route_params_t )
>;
//
// express_request_handler_t
//
using express_request_handler_t =
generic_express_request_handler_t< no_extra_data_factory_t::data_t >;
//
// generic_express_route_entry_t
//
template<
typename Regex_Engine,
typename Extra_Data_Factory >
class generic_express_route_entry_t
{
public:
using actual_request_handler_t = generic_express_request_handler_t<
typename Extra_Data_Factory::data_t
>;
using actual_request_handle_t = generic_request_handle_t<
typename Extra_Data_Factory::data_t
>;
private:
using matcher_init_data_t =
path2regex::impl::route_regex_matcher_data_t<
impl::route_params_appender_t,
Regex_Engine >;
template< typename Method_Matcher >
generic_express_route_entry_t(
Method_Matcher && method_matcher,
matcher_init_data_t matcher_data,
actual_request_handler_t handler )
: m_matcher{
std::forward<Method_Matcher>( method_matcher ),
std::move( matcher_data.m_regex ),
std::move( matcher_data.m_named_params_buffer ),
std::move( matcher_data.m_param_appender_sequence ) }
, m_handler{ std::move( handler ) }
{}
public:
generic_express_route_entry_t(
const generic_express_route_entry_t & ) = delete;
generic_express_route_entry_t & operator=(
const generic_express_route_entry_t & ) = delete;
generic_express_route_entry_t() = default;
generic_express_route_entry_t(
generic_express_route_entry_t && ) = default;
generic_express_route_entry_t &
operator=( generic_express_route_entry_t && ) = default;
template< typename Method_Matcher >
generic_express_route_entry_t(
Method_Matcher && method_matcher,
string_view_t route_path,
const path2regex::options_t & options,
actual_request_handler_t handler )
: generic_express_route_entry_t{
std::forward<Method_Matcher>( method_matcher ),
path2regex::path2regex< impl::route_params_appender_t, Regex_Engine >(
route_path,
options ),
std::move( handler ) }
{}
template< typename Method_Matcher >
generic_express_route_entry_t(
Method_Matcher && method_matcher,
string_view_t route_path,
actual_request_handler_t handler )
: generic_express_route_entry_t{
std::forward<Method_Matcher>( method_matcher ),
route_path,
path2regex::options_t{},
std::move( handler ) }
{}
RESTINIO_NODISCARD
bool
match(
const http_request_header_t & h,
impl::target_path_holder_t & target_path,
route_params_t & params ) const
{
return m_matcher( h, target_path, params );
}
RESTINIO_NODISCARD
request_handling_status_t
handle( actual_request_handle_t rh, route_params_t rp ) const
{
return m_handler( std::move( rh ), std::move( rp ) );
}
private:
impl::route_matcher_t< Regex_Engine > m_matcher;
actual_request_handler_t m_handler;
};
//
// express_route_entry_t
//
template<
typename Regex_Engine = std_regex_engine_t >
using express_route_entry_t = generic_express_route_entry_t<
Regex_Engine,
no_extra_data_factory_t >;
//
// generic_express_router_t
//
template<
typename Regex_Engine,
typename Extra_Data_Factory >
class generic_express_router_t
{
public:
using actual_request_handle_t =
generic_request_handle_t< typename Extra_Data_Factory::data_t >;
using actual_request_handler_t =
typename generic_express_route_entry_t<
Regex_Engine,
Extra_Data_Factory
>::actual_request_handler_t;
using non_matched_handler_t =
generic_non_matched_request_handler_t<
typename Extra_Data_Factory::data_t
>;
generic_express_router_t() = default;
generic_express_router_t( generic_express_router_t && ) = default;
RESTINIO_NODISCARD
request_handling_status_t
operator()( actual_request_handle_t req ) const
{
impl::target_path_holder_t target_path{ req->header().path() };
route_params_t params;
for( const auto & entry : m_handlers )
{
if( entry.match( req->header(), target_path, params ) )
{
return entry.handle( std::move( req ), std::move( params ) );
}
}
// Here: none of the routes matches this handler.
if( m_non_matched_request_handler )
{
// If non matched request handler is set
// then call it.
return m_non_matched_request_handler( std::move( req ) );
}
return request_not_handled();
}
template< typename Method_Matcher >
void
add_handler(
Method_Matcher && method_matcher,
string_view_t route_path,
actual_request_handler_t handler )
{
add_handler(
std::forward<Method_Matcher>(method_matcher),
route_path,
path2regex::options_t{},
std::move( handler ) );
}
template< typename Method_Matcher >
void
add_handler(
Method_Matcher && method_matcher,
string_view_t route_path,
const path2regex::options_t & options,
actual_request_handler_t handler )
{
m_handlers.emplace_back(
std::forward<Method_Matcher>(method_matcher),
route_path,
options,
std::move( handler ) );
}
void
http_delete(
string_view_t route_path,
actual_request_handler_t handler )
{
add_handler(
http_method_delete(),
route_path,
std::move( handler ) );
}
void
http_delete(
string_view_t route_path,
const path2regex::options_t & options,
actual_request_handler_t handler )
{
add_handler(
http_method_delete(),
route_path,
options,
std::move( handler ) );
}
void
http_get(
string_view_t route_path,
actual_request_handler_t handler )
{
add_handler(
http_method_get(),
route_path,
std::move( handler ) );
}
void
http_get(
string_view_t route_path,
const path2regex::options_t & options,
actual_request_handler_t handler )
{
add_handler(
http_method_get(),
route_path,
options,
std::move( handler ) );
}
void
http_head(
string_view_t route_path,
actual_request_handler_t handler )
{
add_handler(
http_method_head(),
route_path,
std::move( handler ) );
}
void
http_head(
string_view_t route_path,
const path2regex::options_t & options,
actual_request_handler_t handler )
{
add_handler(
http_method_head(),
route_path,
options,
std::move( handler ) );
}
void
http_post(
string_view_t route_path,
actual_request_handler_t handler )
{
add_handler(
http_method_post(),
route_path,
std::move( handler ) );
}
void
http_post(
string_view_t route_path,
const path2regex::options_t & options,
actual_request_handler_t handler )
{
add_handler(
http_method_post(),
route_path,
options,
std::move( handler ) );
}
void
http_put(
string_view_t route_path,
actual_request_handler_t handler )
{
add_handler(
http_method_put(),
route_path,
std::move( handler ) );
}
void
http_put(
string_view_t route_path,
const path2regex::options_t & options,
actual_request_handler_t handler )
{
add_handler(
http_method_put(),
route_path,
options,
std::move( handler ) );
}
void
non_matched_request_handler( non_matched_handler_t nmrh )
{
m_non_matched_request_handler = std::move( nmrh );
}
private:
using route_entry_t = generic_express_route_entry_t<
Regex_Engine,
Extra_Data_Factory
>;
std::vector< route_entry_t > m_handlers;
non_matched_handler_t m_non_matched_request_handler;
};
//
// express_router_t
//
template<
typename Regex_Engine = std_regex_engine_t >
using express_router_t = generic_express_router_t<
Regex_Engine,
no_extra_data_factory_t >;
} /* namespace router */
template < typename Value_Type >
Value_Type
get( const router::route_params_t & params, string_view_t key )
{
return get< Value_Type >( params[ key ] );
}
template < typename Value_Type >
Value_Type
get( const router::route_params_t & params, std::size_t index )
{
return get< Value_Type >( params[ index ] );
}
} /* namespace restinio */
nonstd::optional_lite::optional
class optional
Definition: optional.hpp:932
restinio::exception_t
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
restinio::http_method_id_t
A type for representation of HTTP method ID.
Definition: http_headers.hpp:1745
restinio::path2regex::options_t
Options for matching routes.
Definition: path2regex.hpp:92
restinio::router::generic_express_route_entry_t
A single generic express route entry.
Definition: express.hpp:477
restinio::router::generic_express_route_entry_t::match
RESTINIO_NODISCARD bool match(const http_request_header_t &h, impl::target_path_holder_t &target_path, route_params_t &params) const
Checks if request header matches entry, and if so, set route params.
Definition: express.hpp:548
restinio::router::generic_express_route_entry_t::generic_express_route_entry_t
generic_express_route_entry_t(Method_Matcher &&method_matcher, matcher_init_data_t matcher_data, actual_request_handler_t handler)
Definition: express.hpp:493
restinio::router::generic_express_route_entry_t::actual_request_handler_t
generic_express_request_handler_t< typename Extra_Data_Factory::data_t > actual_request_handler_t
Definition: express.hpp:481
restinio::router::generic_express_route_entry_t::operator=
generic_express_route_entry_t & operator=(const generic_express_route_entry_t &)=delete
restinio::router::generic_express_route_entry_t::handle
RESTINIO_NODISCARD request_handling_status_t handle(actual_request_handle_t rh, route_params_t rp) const
Calls a handler of given request with given params.
Definition: express.hpp:559
restinio::router::generic_express_route_entry_t::generic_express_route_entry_t
generic_express_route_entry_t(Method_Matcher &&method_matcher, string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
Definition: express.hpp:519
restinio::router::generic_express_route_entry_t::generic_express_route_entry_t
generic_express_route_entry_t(generic_express_route_entry_t &&)=default
restinio::router::generic_express_route_entry_t::actual_request_handle_t
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
Definition: express.hpp:484
restinio::router::generic_express_route_entry_t::generic_express_route_entry_t
generic_express_route_entry_t(Method_Matcher &&method_matcher, string_view_t route_path, actual_request_handler_t handler)
Definition: express.hpp:533
restinio::router::generic_express_route_entry_t::operator=
generic_express_route_entry_t & operator=(generic_express_route_entry_t &&)=default
restinio::router::generic_express_route_entry_t::m_handler
actual_request_handler_t m_handler
Definition: express.hpp:566
restinio::router::generic_express_route_entry_t::generic_express_route_entry_t
generic_express_route_entry_t()=default
restinio::router::generic_express_route_entry_t::generic_express_route_entry_t
generic_express_route_entry_t(const generic_express_route_entry_t &)=delete
restinio::router::generic_express_route_entry_t::m_matcher
impl::route_matcher_t< Regex_Engine > m_matcher
Definition: express.hpp:565
restinio::router::generic_express_router_t
Generic Express.js style router.
Definition: express.hpp:616
restinio::router::generic_express_router_t::http_post
void http_post(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
Definition: express.hpp:774
restinio::router::generic_express_router_t::http_get
void http_get(string_view_t route_path, actual_request_handler_t handler)
Definition: express.hpp:715
restinio::router::generic_express_router_t::http_put
void http_put(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
Definition: express.hpp:798
restinio::router::generic_express_router_t::non_matched_handler_t
generic_non_matched_request_handler_t< typename Extra_Data_Factory::data_t > non_matched_handler_t
Definition: express.hpp:628
restinio::router::generic_express_router_t::non_matched_request_handler
void non_matched_request_handler(non_matched_handler_t nmrh)
Set handler for requests that don't match any route.
Definition: express.hpp:813
restinio::router::generic_express_router_t::operator()
RESTINIO_NODISCARD request_handling_status_t operator()(actual_request_handle_t req) const
Definition: express.hpp:635
restinio::router::generic_express_router_t::m_non_matched_request_handler
non_matched_handler_t m_non_matched_request_handler
Handler that is called for requests that don't match any route.
Definition: express.hpp:828
restinio::router::generic_express_router_t::http_head
void http_head(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
Definition: express.hpp:750
restinio::router::generic_express_router_t::generic_express_router_t
generic_express_router_t()=default
restinio::router::generic_express_router_t::http_delete
void http_delete(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
Definition: express.hpp:702
restinio::router::generic_express_router_t::actual_request_handle_t
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
Definition: express.hpp:619
restinio::router::generic_express_router_t::http_delete
void http_delete(string_view_t route_path, actual_request_handler_t handler)
Definition: express.hpp:691
restinio::router::generic_express_router_t::m_handlers
std::vector< route_entry_t > m_handlers
A list of existing routes.
Definition: express.hpp:825
restinio::router::generic_express_router_t::add_handler
void add_handler(Method_Matcher &&method_matcher, string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
Definition: express.hpp:677
restinio::router::generic_express_router_t::http_put
void http_put(string_view_t route_path, actual_request_handler_t handler)
Definition: express.hpp:787
restinio::router::generic_express_router_t::http_head
void http_head(string_view_t route_path, actual_request_handler_t handler)
Definition: express.hpp:739
restinio::router::generic_express_router_t::http_post
void http_post(string_view_t route_path, actual_request_handler_t handler)
Definition: express.hpp:763
restinio::router::generic_express_router_t::http_get
void http_get(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
Definition: express.hpp:726
restinio::router::generic_express_router_t::add_handler
void add_handler(Method_Matcher &&method_matcher, string_view_t route_path, actual_request_handler_t handler)
Add handlers.
Definition: express.hpp:663
restinio::router::generic_express_router_t::generic_express_router_t
generic_express_router_t(generic_express_router_t &&)=default
restinio::router::generic_express_router_t::actual_request_handler_t
typename generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >::actual_request_handler_t actual_request_handler_t
Definition: express.hpp:624
restinio::router::impl::buffered_matcher_holder_t
A special class that allows to hold a copy of small-size method_matchers or a pointer to dynamically ...
Definition: method_matcher.hpp:225
restinio::router::impl::route_matcher_t
A matcher for a given path.
Definition: express.hpp:286
restinio::router::impl::route_matcher_t::route_matcher_t
route_matcher_t(Method_Matcher &&method_matcher, regex_t route_regex, std::shared_ptr< std::string > named_params_buffer, param_appender_sequence_t param_appender_sequence)
Definition: express.hpp:313
restinio::router::impl::route_matcher_t::m_method_matcher
buffered_matcher_holder_t m_method_matcher
HTTP method to match.
Definition: express.hpp:409
restinio::router::impl::route_matcher_t::m_route_regex
regex_t m_route_regex
Regex of a given route.
Definition: express.hpp:412
restinio::router::impl::route_matcher_t::m_param_appender_sequence
param_appender_sequence_t m_param_appender_sequence
Parameters values.
Definition: express.hpp:418
restinio::router::impl::route_matcher_t::match_route
bool match_route(target_path_holder_t &target_path, route_params_t &parameters) const
Try to match a given request target with this route.
Definition: express.hpp:332
restinio::router::impl::route_matcher_t::match_results_t
typename Regex_Engine::match_results_t match_results_t
Definition: express.hpp:289
restinio::router::impl::route_matcher_t::operator()
bool operator()(const http_request_header_t &h, target_path_holder_t &target_path, route_params_t &parameters) const
Definition: express.hpp:398
restinio::router::impl::route_matcher_t::route_matcher_t
route_matcher_t()=default
restinio::router::impl::route_matcher_t::m_named_params_buffer
std::shared_ptr< std::string > m_named_params_buffer
Buffer for named parameters names string views.
Definition: express.hpp:415
restinio::router::impl::route_matcher_t::regex_t
typename Regex_Engine::compiled_regex_t regex_t
Definition: express.hpp:288
restinio::router::impl::route_matcher_t::route_matcher_t
route_matcher_t(route_matcher_t &&)=default
restinio::router::impl::route_matcher_t::route_matcher_t
route_matcher_t(http_method_id_t method, regex_t route_regex, std::shared_ptr< std::string > named_params_buffer, param_appender_sequence_t param_appender_sequence)
Creates matcher with a given parameters.
Definition: express.hpp:292
restinio::router::impl::route_params_appender_t
Helper class for gthering parameters from route.
Definition: express.hpp:245
restinio::router::impl::route_params_appender_t::m_indexed_parameters
route_params_t::indexed_parameters_container_t & m_indexed_parameters
Definition: express.hpp:273
restinio::router::impl::route_params_appender_t::add_indexed_param
void add_indexed_param(string_view_t value)
Definition: express.hpp:266
restinio::router::impl::route_params_appender_t::add_named_param
void add_named_param(string_view_t key, string_view_t value)
Definition: express.hpp:260
restinio::router::impl::route_params_appender_t::m_named_parameters
route_params_t::named_parameters_container_t & m_named_parameters
Definition: express.hpp:272
restinio::router::impl::route_params_appender_t::route_params_appender_t
route_params_appender_t(route_params_appender_t &&)=delete
restinio::router::impl::route_params_appender_t::operator=
route_params_appender_t & operator=(const route_params_appender_t &)=delete
restinio::router::impl::route_params_appender_t::route_params_appender_t
route_params_appender_t(const route_params_appender_t &)=delete
restinio::router::impl::route_params_appender_t::route_params_appender_t
route_params_appender_t(route_params_t::named_parameters_container_t &named_parameters, route_params_t::indexed_parameters_container_t &indexed_parameters)
Definition: express.hpp:247
restinio::router::impl::target_path_holder_t
Helper class for holding a unique instance of char array with target_path value.
Definition: target_path_holder.hpp:46
restinio::router::impl::target_path_holder_t::view
RESTINIO_NODISCARD string_view_t view() const noexcept
Get access to the value of target_path.
Definition: target_path_holder.hpp:86
restinio::router::impl::target_path_holder_t::giveout_data
RESTINIO_NODISCARD data_t giveout_data() noexcept
Give out the value from holder.
Definition: target_path_holder.hpp:99
restinio::router::route_params_t
Parameters extracted from route.
Definition: express.hpp:58
restinio::router::route_params_t::find_named_parameter_with_check
named_parameters_container_t::const_reference find_named_parameter_with_check(string_view_t key) const
Definition: express.hpp:155
restinio::router::route_params_t::indexed_parameters_size
auto indexed_parameters_size() const noexcept
Definition: express.hpp:138
restinio::router::route_params_t::get_param
optional_t< string_view_t > get_param(string_view_t key) const noexcept
Get the value of a parameter if it exists.
Definition: express.hpp:112
restinio::router::route_params_t::has
bool has(string_view_t key) const noexcept
Check parameter.
Definition: express.hpp:104
restinio::router::route_params_t::indexed_parameters_container_t
std::vector< string_view_t > indexed_parameters_container_t
Definition: express.hpp:63
restinio::router::route_params_t::match
void match(std::unique_ptr< char[] > request_target, std::shared_ptr< std::string > key_names_buffer, string_view_t match, named_parameters_container_t named_parameters, indexed_parameters_container_t indexed_parameters)
Definition: express.hpp:69
restinio::router::route_params_t::route_params_t
route_params_t(const route_params_t &)=delete
restinio::router::route_params_t::m_request_target
std::unique_ptr< char[] > m_request_target
A raw request target.
Definition: express.hpp:180
restinio::router::route_params_t::named_parameters_container_t
std::vector< std::pair< string_view_t, string_view_t > > named_parameters_container_t
Definition: express.hpp:61
restinio::router::route_params_t::match
string_view_t match() const noexcept
Matched route.
Definition: express.hpp:93
restinio::router::route_params_t::route_params_t
route_params_t()=default
restinio::router::route_params_t::m_named_parameters
named_parameters_container_t m_named_parameters
Named params.
Definition: express.hpp:189
restinio::router::route_params_t::operator=
route_params_t & operator=(route_params_t &&)=default
restinio::router::route_params_t::named_parameters_size
auto named_parameters_size() const noexcept
Get number of parameters.
Definition: express.hpp:137
restinio::router::route_params_t::m_indexed_parameters
indexed_parameters_container_t m_indexed_parameters
Indexed params.
Definition: express.hpp:192
restinio::router::route_params_t::route_params_t
route_params_t(route_params_t &&)=default
restinio::router::route_params_t::operator[]
string_view_t operator[](string_view_t key) const
Get named parameter.
Definition: express.hpp:97
restinio::router::route_params_t::find_named_parameter
named_parameters_container_t::const_iterator find_named_parameter(string_view_t key) const noexcept
Definition: express.hpp:143
restinio::router::route_params_t::m_match
string_view_t m_match
Matched pattern.
Definition: express.hpp:186
restinio::router::route_params_t::m_key_names_buffer
std::shared_ptr< std::string > m_key_names_buffer
Shared buffer for string_view of named parameterts names.
Definition: express.hpp:183
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:36
from_string.hpp
RESTINIO_FMT_FORMAT_STRING
#define RESTINIO_FMT_FORMAT_STRING(s)
Definition: include_fmtlib.hpp:92
method_matcher.hpp
Stuff related to method_matchers.
restinio::path2regex::param_appender_sequence_t
std::vector< param_appender_t< Route_Param_Appender > > param_appender_sequence_t
A sequence of appenders for submatches.
Definition: path2regex.hpp:272
restinio::router::impl::param_appender_sequence_t
path2regex::param_appender_sequence_t< route_params_appender_t > param_appender_sequence_t
Definition: express.hpp:277
restinio::router::generic_non_matched_request_handler_t
std::function< request_handling_status_t(generic_request_handle_t< Extra_Data >) > generic_non_matched_request_handler_t
A generic type of handler for non-matched requests.
Definition: non_matched_request_handler.hpp:45
restinio::router::generic_express_request_handler_t
std::function< request_handling_status_t(generic_request_handle_t< Extra_Data >, route_params_t) > generic_express_request_handler_t
Type of generic handler for one route.
Definition: express.hpp:447
restinio::router::express_request_handler_t
generic_express_request_handler_t< no_extra_data_factory_t::data_t > express_request_handler_t
Type of a handler for one route in the case when there is no extra-data in request object.
Definition: express.hpp:461
restinio
Definition: asio_include.hpp:21
restinio::request_not_handled
RESTINIO_NODISCARD constexpr request_handling_status_t request_not_handled() noexcept
Definition: common_types.hpp:63
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::generic_request_handle_t
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
Definition: request_handler.hpp:455
restinio::request_handling_status_t
request_handling_status_t
Request handling status.
Definition: common_types.hpp:26
restinio::get
Value_Type get(const router::route_params_t &params, string_view_t key)
Cast named parameter value to a given type.
Definition: express.hpp:854
std
STL namespace.
non_matched_request_handler.hpp
The definition of the non_matched_request_handler type.
optional.hpp
path2regex.hpp
percent_encoding.hpp
std_regex_engine.hpp
restinio::http_request_header_t
Req header.
Definition: http_headers.hpp:1860
restinio::http_request_header_t::method
http_method_id_t method() const noexcept
Definition: http_headers.hpp:1882
restinio::no_extra_data_factory_t
The default extra-data-factory to be used in server's traits if a user doesn't specify own one.
Definition: request_handler.hpp:77
restinio::path2regex::impl::route_regex_matcher_data_t
Resulting regex and param extraction for a specific route.
Definition: path2regex.hpp:752
restinio::router::impl::route_params_accessor_t
Route params private internals accessor.
Definition: express.hpp:204
restinio::router::impl::route_params_accessor_t::named_parameters
static const auto & named_parameters(const route_params_t &rp) noexcept
Get values containers for all parameters (used in unit tests).
Definition: express.hpp:226
restinio::router::impl::route_params_accessor_t::indexed_parameters
static const auto & indexed_parameters(const route_params_t &rp) noexcept
Definition: express.hpp:232
restinio::router::impl::route_params_accessor_t::match
static void match(route_params_t &rp, std::unique_ptr< char[] > request_target, std::shared_ptr< std::string > key_names_buffer, string_view_t match_, route_params_t::named_parameters_container_t named_parameters, route_params_t::indexed_parameters_container_t indexed_parameters)
Init parameters with a matched route params.
Definition: express.hpp:207
restinio::router::method_matcher_t::match
virtual RESTINIO_NODISCARD bool match(const http_method_id_t &method) const noexcept=0
Is the specified method can be applied to a route?
restinio::router::std_regex_engine_t
Regex engine implementation for using with standard regex implementation.
Definition: std_regex_engine.hpp:25
target_path_holder.hpp
Implementation of target_path_holder helper class.
const
#define const
Definition: zconf.h:230