14 #include <restinio/router/impl/target_path_holder.hpp> 15 #include <restinio/router/non_matched_request_handler.hpp> 16 #include <restinio/router/method_matcher.hpp> 18 #include <restinio/helpers/easy_parser.hpp> 54 template<
typename Extra_Data >
105 template<
typename Extra_Data,
typename Producer,
typename Handler >
118 using actual_request_handle_t =
122 typename Method_Matcher,
123 typename Producer_Arg,
124 typename Handler_Arg >
126 Method_Matcher && method_matcher,
127 Producer_Arg && producer,
128 Handler_Arg && handler )
165 template<
typename Unescape_Traits >
189 template<
typename Producer, std::size_t Index >
202 template<
typename Producer_Arg >
211 template<
typename Producer_Arg >
232 template< std::size_t Size >
247 const char (&fragment)[Size] )
293 template<
typename H,
typename R,
bool Is_Producer >
294 struct add_type_if_necessary_impl;
298 template<
class...>
class To,
299 typename... Results >
300 struct add_type_if_necessary_impl< H, To<Results...>,
false >
302 using type = To<Results...>;
307 template<
class...>
class To,
308 typename... Results >
309 struct add_type_if_necessary_impl< H, To<Results...>,
true >
311 using type = To<Results...,
typename H::result_type>;
315 template<
typename H,
typename R >
321 template<
typename From,
typename To >
322 struct result_tuple_detector;
326 template<
class...>
class From,
328 template<
class...>
class To,
329 typename... Results >
330 struct result_tuple_detector< From<Sources...>, To<Results...> >
332 using type =
typename result_tuple_detector<
333 meta::tail_of_t< Sources... >,
334 typename add_type_if_necessary<
335 meta::head_of_t< Sources... >,
336 To< Results... > >::type
341 template<
class...>
class From,
342 template<
class...>
class To,
343 typename... Results >
344 struct result_tuple_detector< From<>, To<Results...> >
346 using type = To<Results...>;
350 template<
typename Args_Type_List >
360 template<
typename Args_Type_List >
372 template<
typename T,
bool Is_Producer, std::size_t Current_Index >
375 using clause_type = T;
379 template< std::size_t Size, std::size_t Current_Index >
400 template<
typename T, std::size_t Current_Index >
411 template<
typename From,
typename To, std::size_t Current_Index >
412 struct clauses_type_maker;
415 template<
class...>
class From,
417 template<
class...>
class To,
419 std::size_t Current_Index >
420 struct clauses_type_maker< From<Sources...>, To<Results...>, Current_Index >
423 using head_type = meta::head_of_t< Sources... >;
425 using one_clause_type = one_clause_type_processor<
427 ep::impl::is_producer_v<head_type>,
431 using type =
typename clauses_type_maker<
432 meta::tail_of_t< Sources... >,
433 To< Results...,
typename one_clause_type::clause_type >,
434 one_clause_type::next_index >::type;
438 template<
class...>
class From,
439 template<
class...>
class To,
441 std::size_t Current_Index >
442 struct clauses_type_maker< From<>, To<Results...>, Current_Index >
444 using type = To< Results... >;
449 template<
typename Args_Type_List >
460 template<
typename Args_Type_List >
480 template<
typename T >
512 template<
typename... Args >
515 static_assert( 0u !=
sizeof...(Args),
"Args can't be an empty list" );
537 typename Target_Type,
538 typename Subitems_Tuple >
547 template<
typename Extra_Data,
typename Handler >
551 const generic_request_handle_t< Extra_Data > & req,
553 typename base_type_t::result_type &
type )
555 return handler( req, type );
566 std::size_t... Indexes >
570 const generic_request_handle_t< Extra_Data > & req,
574 return std::forward<F>(what)(
576 std::get<Indexes>(std::forward<Tuple>(params))... );
589 template<
typename F,
typename Extra_Data,
typename Tuple >
593 const generic_request_handle_t< Extra_Data > & req,
596 return call_with_tuple_impl(
597 std::forward<F>(what),
599 std::forward<Tuple>(params),
600 std::make_index_sequence<
601 std::tuple_size< std::remove_reference_t<Tuple> >::value
620 typename Target_Type,
621 typename Subitems_Tuple >
630 template<
typename User_Type,
typename Handler >
634 const generic_request_handle_t< User_Type > & req,
636 typename base_type_t::result_type &
type )
638 return path_to_params_details::call_with_tuple( handler, req, type );
688 template<
typename... Args >
694 using result_tuple_type =
typename dsl_processor::result_tuple;
695 using subclauses_tuple_type =
typename dsl_processor::clauses_tuple;
699 subclauses_tuple_type >;
701 return producer_type{
702 subclauses_tuple_type{ std::forward<Args>(args)... }
742 template<
typename... Args >
748 using result_tuple_type =
typename dsl_processor::result_tuple;
749 using subclauses_tuple_type =
typename dsl_processor::clauses_tuple;
753 subclauses_tuple_type >;
755 return producer_type{
756 subclauses_tuple_type{ std::forward<Args>(args)... }
804 return produce< std::string >(
806 any_symbol_if_not_p( separator ) >> to_container() ) );
855 template<
typename Unescape_Traits =
945 template<
typename Extra_Data_Factory >
948 using extra_data_t =
typename Extra_Data_Factory::data_t;
997 typename Method_Matcher,
998 typename Route_Producer,
1002 Method_Matcher && method_matcher,
1003 Route_Producer && route,
1004 Handler && handler )
1023 template<
typename Route_Producer,
typename Handler >
1026 Route_Producer && route,
1027 Handler && handler )
1036 template<
typename Route_Producer,
typename Handler >
1039 Route_Producer && route,
1040 Handler && handler )
1049 template<
typename Route_Producer,
typename Handler >
1052 Route_Producer && route,
1053 Handler && handler )
1062 template<
typename Route_Producer,
typename Handler >
1065 Route_Producer && route,
1066 Handler && handler )
1075 template<
typename Route_Producer,
typename Handler >
1078 Route_Producer && route,
1079 Handler && handler )
1090 generic_non_matched_request_handler_t< extra_data_t > nmrh )
virtual expected_t< request_handling_status_t, no_match_t > try_handle(const actual_request_handle_t &req, target_path_holder_t &target_path) const =0
An attempt to match a request against the route.
special_exact_fragment_clause_t(string_view_t value)
void non_matched_request_handler(generic_non_matched_request_handler_t< extra_data_t > nmrh)
Set handler for requests that don't match any route.
static constexpr std::size_t next_index
void http_put(Route_Producer &&route, Handler &&handler)
Set handler for HTTP PUT request.
generic_easy_parser_router_t & operator=(const generic_easy_parser_router_t &)=delete
void http_head(Route_Producer &&route, Handler &&handler)
Set handler for HTTP HEAD request.
decltype(auto) call_with_tuple(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &¶ms)
A helper function to call a request-handler with a tuple.
expected_t< request_handling_status_t, no_match_t > try_handle(const actual_request_handle_t &req, target_path_holder_t &target_path) const override
An attempt to match a request against the route.
static auto invoke_handler(const generic_request_handle_t< Extra_Data > &req, Handler &&handler, typename base_type_t::result_type &type)
entries_container_t m_entries
Helper type to indicate a negative match attempt.
An implementation of a producer for path_to_tuple case.
void http_delete(Route_Producer &&route, Handler &&handler)
Set handler for HTTP DELETE request.
A special analog of std::decay meta-function that is handles array differently.
auto unescape()
A factory for unescape_transformer.
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
request_handling_status_t operator()(actual_request_handle_t req) const
A generic request router that uses easy_parser for matching requests with handlers.
generic_easy_parser_router_t(generic_easy_parser_router_t &&)=default
A special clause type for case when exact_fragment_producer should be used without storing its value...
Producer m_producer
Parser of a route and producer of argument(s) for request handler.
actual_router_entry_t(Method_Matcher &&method_matcher, Producer_Arg &&producer, Handler_Arg &&handler)
Handler m_handler
Request handler to be used.
restinio::router::impl::buffered_matcher_holder_t m_method_matcher
HTTP method to match.
special_produce_tuple_item_clause_t(Producer_Arg &&producer)
The main meta-function for processing route DSL.
static Producer make_producer(Producer_Arg &&producer)
void http_get(Route_Producer &&route, Handler &&handler)
Set handler for HTTP GET request.
A special case of produce-consume clause where the produced value is stored into a tuple...
A special clause type for case when exact_fixed_size_fragment_producer should be used without storing...
An interface for one entry of easy_parser-based router.
generic_easy_parser_router_t(const generic_easy_parser_router_t &)=delete
void add_handler(Method_Matcher &&method_matcher, Route_Producer &&route, Handler &&handler)
static auto invoke_handler(const generic_request_handle_t< User_Type > &req, Handler &&handler, typename base_type_t::result_type &type)
decltype(auto) call_with_tuple_impl(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &¶ms, std::index_sequence< Indexes... >)
An actual implementation of router_entry interface.
An implementation of a producer for path_to_params case.
static constexpr std::size_t next_index
void http_post(Route_Producer &&route, Handler &&handler)
Set handler for HTTP POST request.
auto path_fragment_p(char separator='/')
A factory that creates a string-producer that extracts a sequence on symbols until the separator will...
auto path_to_params(Args &&...args)
Describe a route for a handler that accepts params from the route in form of a list of separate argum...
static constexpr std::size_t next_index
special_exact_fixed_size_fragment_clause_t(const char(&fragment)[Size])
auto path_to_tuple(Args &&...args)
Describe a route for a handler that accepts params from the route in form of a tuple.
virtual ~router_entry_t()=default
static constexpr std::size_t next_index
generic_easy_parser_router_t & operator=(generic_easy_parser_router_t &&)=default
generic_non_matched_request_handler_t< extra_data_t > m_non_matched_request_handler
Handler that is called for requests that don't match any route.
generic_easy_parser_router_t()=default