RESTinio

easy_parser_router.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
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>
17
18#include <restinio/helpers/easy_parser.hpp>
19
20#include <vector>
21
22 namespace restinio
23{
24
25 namespace router
26{
27
28 namespace easy_parser_router
29{
30
31 namespace impl
32{
33
34 namespace meta = restinio::utils::metaprogramming;
35 namespace ep = restinio::easy_parser;
36
37 using target_path_holder_t = restinio::router::impl::target_path_holder_t;
38
44 struct no_match_t {};
45
54 template< typename Extra_Data >
55 class router_entry_t
56{
57 public:
58 using actual_request_handle_t = generic_request_handle_t< Extra_Data >;
59
60 virtual ~router_entry_t() = default;
61
63
70 RESTINIO_NODISCARD
71 virtual expected_t< request_handling_status_t, no_match_t >
72 try_handle(
73 const actual_request_handle_t & req,
74 target_path_holder_t & target_path ) const = 0;
75};
76
85 template< typename Extra_Data >
86 using router_entry_unique_ptr_t =
87 std::unique_ptr< router_entry_t< Extra_Data > >;
88
89//
90// actual_router_entry_t
91//
105 template< typename Extra_Data, typename Producer, typename Handler >
106 class actual_router_entry_t : public router_entry_t< Extra_Data >
107{
108 //FIXME: compatibility between Extra_Data and Handler should be
109 //checked by static_assert. If it's possible.
110
112 restinio::router::impl::buffered_matcher_holder_t m_method_matcher;
113
115 Producer m_producer;
116
118 Handler m_handler;
119
120 public:
121 using actual_request_handle_t =
122 typename router_entry_t<Extra_Data>::actual_request_handle_t;
123
124 template<
125 typename Method_Matcher,
126 typename Producer_Arg,
127 typename Handler_Arg >
128 actual_router_entry_t(
129 Method_Matcher && method_matcher,
130 Producer_Arg && producer,
131 Handler_Arg && handler )
132 : m_producer{ std::forward<Producer_Arg>(producer) }
133 , m_handler{ std::forward<Handler_Arg>(handler) }
134 {
135 assign( m_method_matcher, std::forward<Method_Matcher>(method_matcher) );
136 }
137
138 RESTINIO_NODISCARD
139 expected_t< request_handling_status_t, no_match_t >
140 try_handle(
141 const actual_request_handle_t & req,
142 target_path_holder_t & target_path ) const override
143 {
144 if( m_method_matcher->match( req->header().method() ) )
145 {
146 auto parse_result = easy_parser::try_parse(
147 target_path.view(),
148 m_producer );
149 if( parse_result )
150 {
151 return Producer::invoke_handler( req, m_handler, *parse_result );
152 }
153 }
154
155 return make_unexpected( no_match_t{} );
156 }
157};
158
159//
160// unescape_transformer_t
161//
168 template< typename Unescape_Traits >
169 struct unescape_transformer_t
170 : public restinio::easy_parser::impl::transformer_tag< std::string >
171{
172 using input_type = std::string;
173
174 RESTINIO_NODISCARD
175 result_type
176 transform( input_type && input ) const
177 {
178 return restinio::utils::unescape_percent_encoding< Unescape_Traits >(
179 input );
180 }
181};
182
183//
184// special_produce_tuple_item_clause_t
185//
192 template< typename Producer, std::size_t Index >
193 class special_produce_tuple_item_clause_t
194 : public ep::impl::consume_value_clause_t<
195 Producer,
196 ep::impl::tuple_item_consumer_t<Index> >
197{
198 using consumer_t = ep::impl::tuple_item_consumer_t<Index>;
199
200 using base_type_t = ep::impl::consume_value_clause_t<
201 Producer,
202 consumer_t >;
203
204 // NOTE: this is just a workaround for VS2017.
205 template< typename Producer_Arg >
206 RESTINIO_NODISCARD
207 static Producer
208 make_producer( Producer_Arg && producer )
209 {
210 return { std::forward<Producer_Arg>(producer) };
211 }
212
213 public:
214 template< typename Producer_Arg >
215 special_produce_tuple_item_clause_t( Producer_Arg && producer )
216 : base_type_t{
217 make_producer( std::forward<Producer_Arg>(producer) ),
218 consumer_t{} }
219 {}
220};
221
222//
223// special_exact_fixed_size_fragment_clause_t
224//
235 template< std::size_t Size >
236 class special_exact_fixed_size_fragment_clause_t
237 : public ep::impl::consume_value_clause_t<
238 ep::impl::exact_fixed_size_fragment_producer_t<Size>,
239 ep::impl::any_value_skipper_t >
240{
241 using producer_t = ep::impl::exact_fixed_size_fragment_producer_t<Size>;
242 using consumer_t = ep::impl::any_value_skipper_t;
243
244 using base_type_t = ep::impl::consume_value_clause_t<
245 producer_t,
246 consumer_t >;
247
248 public:
249 special_exact_fixed_size_fragment_clause_t(
250 const char (&fragment)[Size] )
251 : base_type_t{ producer_t{ fragment }, consumer_t{} }
252 {}
253};
254
255//
256// special_exact_fragment_clause_t
257//
268 class special_exact_fragment_clause_t
269 : public ep::impl::consume_value_clause_t<
270 ep::impl::exact_fragment_producer_t,
271 ep::impl::any_value_skipper_t >
272{
273 using producer_t = ep::impl::exact_fragment_producer_t;
274 using consumer_t = ep::impl::any_value_skipper_t;
275
276 using base_type_t = ep::impl::consume_value_clause_t<
277 producer_t,
278 consumer_t >;
279
280 public:
281 special_exact_fragment_clause_t( std::string value )
282 : base_type_t{ producer_t{ std::move(value) }, consumer_t{} }
283 {}
284
285 special_exact_fragment_clause_t( string_view_t value )
286 : base_type_t{
287 producer_t{ std::string{ value.data(), value.size() } },
288 consumer_t{} }
289 {}
290};
291
292 namespace dsl_details
293{
294
295// Adds type H to type list R if Is_Producer is true.
296 template< typename H, typename R, bool Is_Producer >
297 struct add_type_if_necessary_impl;
298
299 template<
300 typename H,
301 template<class...> class To,
302 typename... Results >
303 struct add_type_if_necessary_impl< H, To<Results...>, false >
304{
305 using type = To<Results...>;
306};
307
308 template<
309 typename H,
310 template<class...> class To,
311 typename... Results >
312 struct add_type_if_necessary_impl< H, To<Results...>, true >
313{
314 using type = To<Results..., typename H::result_type>;
315};
316
317// Adds type H to type list R if H is a producer.
318 template< typename H, typename R >
319 struct add_type_if_necessary
320 : add_type_if_necessary_impl< H, R, ep::impl::is_producer_v<H> >
321{};
322
323// Produces a type-list of producers from type-list From.
324 template< typename From, typename To >
325 struct result_tuple_detector;
326
327// Adds a type from Sources to Results only if this type is a producer.
328 template<
329 template<class...> class From,
330 typename... Sources,
331 template<class...> class To,
332 typename... Results >
333 struct result_tuple_detector< From<Sources...>, To<Results...> >
334{
335 using type = typename result_tuple_detector<
336 meta::tail_of_t< Sources... >,
337 typename add_type_if_necessary<
338 meta::head_of_t< Sources... >,
339 To< Results... > >::type
340 >::type;
341};
342
343 template<
344 template<class...> class From,
345 template<class...> class To,
346 typename... Results >
347 struct result_tuple_detector< From<>, To<Results...> >
348{
349 using type = To<Results...>;
350};
351
352// Produces a type of std::tuple of producers from type-list Args_Type_List.
353 template< typename Args_Type_List >
354 struct detect_result_tuple
355{
356 using type = meta::rename_t<
357 typename result_tuple_detector<
358 Args_Type_List,
359 meta::type_list<> >::type,
360 std::tuple >;
361};
362
363 template< typename Args_Type_List >
364 using detect_result_tuple_t = typename detect_result_tuple<Args_Type_List>::type;
365
366// Detects an appropriate type of clause for T.
367// If T is a producer then there will be a new clause that
368// consumes a value T produces.
369// In that case Current_Index will also be incremented.
370//
371// If T is not a producer then Current_Index will be kept.
372//
373// If T is a string literal, or std::string, or string_view
374// then T will be replaced by a special clause.
375 template< typename T, bool Is_Producer, std::size_t Current_Index >
376 struct one_clause_type_processor
377{
378 using clause_type = T;
379 static constexpr std::size_t next_index = Current_Index;
380};
381
382 template< std::size_t Size, std::size_t Current_Index >
383 struct one_clause_type_processor<const char[Size], false, Current_Index>
384{
385 using clause_type = special_exact_fixed_size_fragment_clause_t<Size>;
386 static constexpr std::size_t next_index = Current_Index;
387};
388
389 template< std::size_t Current_Index >
390 struct one_clause_type_processor<std::string, false, Current_Index>
391{
392 using clause_type = special_exact_fragment_clause_t;
393 static constexpr std::size_t next_index = Current_Index;
394};
395
396 template< std::size_t Current_Index >
397 struct one_clause_type_processor<string_view_t, false, Current_Index>
398{
399 using clause_type = special_exact_fragment_clause_t;
400 static constexpr std::size_t next_index = Current_Index;
401};
402
403 template< typename T, std::size_t Current_Index >
404 struct one_clause_type_processor<T, true, Current_Index>
405{
406 using clause_type = special_produce_tuple_item_clause_t< T, Current_Index >;
407 static constexpr std::size_t next_index = Current_Index + 1u;
408};
409
410// Takes a type-list of user-specified types From and produces a
411// typelist of actual clauses types To.
412//
413// The Current_Index should 0 at the first invocation.
414 template< typename From, typename To, std::size_t Current_Index >
415 struct clauses_type_maker;
416
417 template<
418 template<class...> class From,
419 typename... Sources,
420 template<class...> class To,
421 typename... Results,
422 std::size_t Current_Index >
423 struct clauses_type_maker< From<Sources...>, To<Results...>, Current_Index >
424{
425 private:
426 using head_type = meta::head_of_t< Sources... >;
427
428 using one_clause_type = one_clause_type_processor<
429 head_type,
430 ep::impl::is_producer_v<head_type>,
431 Current_Index >;
432
433 public:
434 using type = typename clauses_type_maker<
435 meta::tail_of_t< Sources... >,
436 To< Results..., typename one_clause_type::clause_type >,
437 one_clause_type::next_index >::type;
438};
439
440 template<
441 template<class...> class From,
442 template<class...> class To,
443 typename... Results,
444 std::size_t Current_Index >
445 struct clauses_type_maker< From<>, To<Results...>, Current_Index >
446{
447 using type = To< Results... >;
448};
449
450// Takes a type-list of user-specified types Args_Type_List and produces a
451// typelist of actual clauses types to be used for parsing.
452 template< typename Args_Type_List >
453 struct make_clauses_types
454{
455 using type = meta::rename_t<
456 typename clauses_type_maker<
457 Args_Type_List,
458 meta::type_list<>,
459 0u >::type,
460 std::tuple >;
461};
462
463 template< typename Args_Type_List >
464 using make_clauses_types_t = typename make_clauses_types<Args_Type_List>::type;
465
466//
467// special_decay
468//
483 template< typename T >
484 struct special_decay
485{
486 private:
487 using U = std::remove_reference_t<T>;
488
489 public:
490 using type = typename std::conditional<
491 std::is_array<U>::value,
492 U,
493 std::remove_cv_t<U>
494 >::type;
495};
496
497} /* namespace dsl_details */
498
499//
500// dsl_processor
501//
515 template< typename... Args >
516 struct dsl_processor
517{
518 static_assert( 0u != sizeof...(Args), "Args can't be an empty list" );
519
520 using arg_types = meta::transform_t<
521 dsl_details::special_decay, meta::type_list<Args...> >;
522
523 using result_tuple = dsl_details::detect_result_tuple_t< arg_types >;
524
525 using clauses_tuple = dsl_details::make_clauses_types_t< arg_types >;
526};
527
528//
529// path_to_tuple_producer_t
530//
539 template<
540 typename Target_Type,
541 typename Subitems_Tuple >
542 class path_to_tuple_producer_t
543 : public ep::impl::produce_t< Target_Type, Subitems_Tuple >
544{
545 using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
546
547 public:
548 using base_type_t::base_type_t;
549
550 template< typename Extra_Data, typename Handler >
551 RESTINIO_NODISCARD
552 static auto
553 invoke_handler(
554 const generic_request_handle_t< Extra_Data > & req,
555 Handler && handler,
556 typename base_type_t::result_type & type )
557 {
558 return handler( req, type );
559 }
560};
561
562 namespace path_to_params_details
563{
564
565 template<
566 typename F,
567 typename Extra_Data,
568 typename Tuple,
569 std::size_t... Indexes >
570 decltype(auto)
571 call_with_tuple_impl(
572 F && what,
573 const generic_request_handle_t< Extra_Data > & req,
574 Tuple && params,
575 std::index_sequence<Indexes...> )
576{
577 return std::forward<F>(what)(
578 req,
579 std::get<Indexes>(std::forward<Tuple>(params))... );
580}
581
582//
583// call_with_tuple
584//
592 template< typename F, typename Extra_Data, typename Tuple >
593 decltype(auto)
594 call_with_tuple(
595 F && what,
596 const generic_request_handle_t< Extra_Data > & req,
597 Tuple && params )
598{
599 return call_with_tuple_impl(
600 std::forward<F>(what),
601 req,
602 std::forward<Tuple>(params),
603 std::make_index_sequence<
604 std::tuple_size< std::remove_reference_t<Tuple> >::value
605 >{} );
606}
607
608} /* namespace path_to_params_details */
609
610//
611// path_to_params_producer_t
612//
622 template<
623 typename Target_Type,
624 typename Subitems_Tuple >
625 class path_to_params_producer_t
626 : public ep::impl::produce_t< Target_Type, Subitems_Tuple >
627{
628 using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
629
630 public:
631 using base_type_t::base_type_t;
632
633 template< typename User_Type, typename Handler >
634 RESTINIO_NODISCARD
635 static auto
636 invoke_handler(
637 const generic_request_handle_t< User_Type > & req,
638 Handler && handler,
639 typename base_type_t::result_type & type )
640 {
641 return path_to_params_details::call_with_tuple( handler, req, type );
642 }
643};
644
645} /* namespace impl */
646
647 using namespace restinio::easy_parser;
648
649//
650// path_to_tuple
651//
691 template< typename... Args >
692 RESTINIO_NODISCARD
693 auto
694 path_to_tuple( Args && ...args )
695{
696 using dsl_processor = impl::dsl_processor< Args... >;
697 using result_tuple_type = typename dsl_processor::result_tuple;
698 using subclauses_tuple_type = typename dsl_processor::clauses_tuple;
699
700 using producer_type = impl::path_to_tuple_producer_t<
701 result_tuple_type,
702 subclauses_tuple_type >;
703
704 return producer_type{
705 subclauses_tuple_type{ std::forward<Args>(args)... }
706 };
707}
708
709//
710// path_to_params
711//
745 template< typename... Args >
746 RESTINIO_NODISCARD
747 auto
748 path_to_params( Args && ...args )
749{
750 using dsl_processor = impl::dsl_processor< Args... >;
751 using result_tuple_type = typename dsl_processor::result_tuple;
752 using subclauses_tuple_type = typename dsl_processor::clauses_tuple;
753
754 using producer_type = impl::path_to_params_producer_t<
755 result_tuple_type,
756 subclauses_tuple_type >;
757
758 return producer_type{
759 subclauses_tuple_type{ std::forward<Args>(args)... }
760 };
761}
762
803 RESTINIO_NODISCARD
804 inline auto
805 path_fragment_p( char separator = '/' )
806{
807 return produce< std::string >(
808 repeat( 1, N,
809 any_symbol_if_not_p( separator ) >> to_container() ) );
810}
811
858 template< typename Unescape_Traits =
859 restinio::utils::restinio_default_unescape_traits >
860 RESTINIO_NODISCARD
861 auto
862 unescape()
863{
864 return impl::unescape_transformer_t< Unescape_Traits >{};
865}
866
867} /* namespace easy_parser_router */
868
869//
870// generic_easy_parser_router_t
871//
948 template< typename Extra_Data_Factory >
949 class generic_easy_parser_router_t
950{
951 using extra_data_t = typename Extra_Data_Factory::data_t;
952
953 public:
954 using actual_request_handle_t = generic_request_handle_t< extra_data_t >;
955
956 generic_easy_parser_router_t() = default;
957
958 generic_easy_parser_router_t(
959 const generic_easy_parser_router_t & ) = delete;
960 generic_easy_parser_router_t &
961 operator=( const generic_easy_parser_router_t & ) = delete;
962
963 generic_easy_parser_router_t( generic_easy_parser_router_t && ) = default;
964 generic_easy_parser_router_t &
965 operator=( generic_easy_parser_router_t && ) = default;
966
967 RESTINIO_NODISCARD
968 request_handling_status_t
969 operator()( actual_request_handle_t req ) const
970 {
971 using namespace easy_parser_router::impl;
972
973 // Take care of an optional trailing slash.
974 string_view_t path_to_inspect{ req->header().path() };
975 if( path_to_inspect.size() > 1u && '/' == path_to_inspect.back() )
976 path_to_inspect.remove_suffix( 1u );
977
978 target_path_holder_t target_path{ path_to_inspect };
979 for( const auto & entry : m_entries )
980 {
981 const auto r = entry->try_handle( req, target_path );
982 if( r )
983 {
984 return *r;
985 }
986 }
987
988 // Here: none of the routes matches this handler.
989 if( m_non_matched_request_handler )
990 {
991 // If non matched request handler is set
992 // then call it.
993 return m_non_matched_request_handler( std::move( req ) );
994 }
995
996 return request_not_handled();
997 }
998
999 template<
1000 typename Method_Matcher,
1001 typename Route_Producer,
1002 typename Handler >
1003 void
1004 add_handler(
1005 Method_Matcher && method_matcher,
1006 Route_Producer && route,
1007 Handler && handler )
1008 {
1009 using namespace easy_parser_router::impl;
1010
1011 using producer_type = std::decay_t< Route_Producer >;
1012 using handler_type = std::decay_t< Handler >;
1013
1014 using actual_entry_type = actual_router_entry_t<
1015 extra_data_t, producer_type, handler_type >;
1016
1017 auto entry = std::make_unique< actual_entry_type >(
1018 std::forward<Method_Matcher>(method_matcher),
1019 std::forward<Route_Producer>(route),
1020 std::forward<Handler>(handler) );
1021
1022 m_entries.push_back( std::move(entry) );
1023 }
1024
1026 template< typename Route_Producer, typename Handler >
1027 void
1028 http_get(
1029 Route_Producer && route,
1030 Handler && handler )
1031 {
1032 this->add_handler(
1033 http_method_get(),
1034 std::forward<Route_Producer>(route),
1035 std::forward<Handler>(handler) );
1036 }
1037
1039 template< typename Route_Producer, typename Handler >
1040 void
1041 http_delete(
1042 Route_Producer && route,
1043 Handler && handler )
1044 {
1045 this->add_handler(
1046 http_method_delete(),
1047 std::forward<Route_Producer>(route),
1048 std::forward<Handler>(handler) );
1049 }
1050
1052 template< typename Route_Producer, typename Handler >
1053 void
1054 http_head(
1055 Route_Producer && route,
1056 Handler && handler )
1057 {
1058 this->add_handler(
1059 http_method_head(),
1060 std::forward<Route_Producer>(route),
1061 std::forward<Handler>(handler) );
1062 }
1063
1065 template< typename Route_Producer, typename Handler >
1066 void
1067 http_post(
1068 Route_Producer && route,
1069 Handler && handler )
1070 {
1071 this->add_handler(
1072 http_method_post(),
1073 std::forward<Route_Producer>(route),
1074 std::forward<Handler>(handler) );
1075 }
1076
1078 template< typename Route_Producer, typename Handler >
1079 void
1080 http_put(
1081 Route_Producer && route,
1082 Handler && handler )
1083 {
1084 this->add_handler(
1085 http_method_put(),
1086 std::forward<Route_Producer>(route),
1087 std::forward<Handler>(handler) );
1088 }
1089
1091 void
1092 non_matched_request_handler(
1093 generic_non_matched_request_handler_t< extra_data_t > nmrh )
1094 {
1095 m_non_matched_request_handler= std::move( nmrh );
1096 }
1097
1098 private:
1099 using entries_container_t = std::vector<
1100 easy_parser_router::impl::router_entry_unique_ptr_t< extra_data_t >
1101 >;
1102
1103 entries_container_t m_entries;
1104
1106 generic_non_matched_request_handler_t< extra_data_t >
1107 m_non_matched_request_handler;
1108};
1109
1110//
1111// easy_parser_router_t
1112//
1173 using easy_parser_router_t =
1174 generic_easy_parser_router_t< no_extra_data_factory_t >;
1175
1176} /* namespace router */
1177
1178} /* namespace restinio */
1179
restinio::router::easy_parser_router::impl::actual_router_entry_t
An actual implementation of router_entry interface.
Definition: easy_parser_router.hpp:107
restinio::router::easy_parser_router::impl::actual_router_entry_t::m_producer
Producer m_producer
Parser of a route and producer of argument(s) for request handler.
Definition: easy_parser_router.hpp:115
restinio::router::easy_parser_router::impl::actual_router_entry_t::actual_router_entry_t
actual_router_entry_t(Method_Matcher &&method_matcher, Producer_Arg &&producer, Handler_Arg &&handler)
Definition: easy_parser_router.hpp:128
restinio::router::easy_parser_router::impl::actual_router_entry_t::m_handler
Handler m_handler
Request handler to be used.
Definition: easy_parser_router.hpp:118
restinio::router::easy_parser_router::impl::actual_router_entry_t::try_handle
RESTINIO_NODISCARD 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.
Definition: easy_parser_router.hpp:140
restinio::router::easy_parser_router::impl::actual_router_entry_t::m_method_matcher
restinio::router::impl::buffered_matcher_holder_t m_method_matcher
HTTP method to match.
Definition: easy_parser_router.hpp:112
restinio::router::easy_parser_router::impl::path_to_params_producer_t
An implementation of a producer for path_to_params case.
Definition: easy_parser_router.hpp:627
restinio::router::easy_parser_router::impl::path_to_params_producer_t::invoke_handler
static RESTINIO_NODISCARD auto invoke_handler(const generic_request_handle_t< User_Type > &req, Handler &&handler, typename base_type_t::result_type &type)
Definition: easy_parser_router.hpp:636
restinio::router::easy_parser_router::impl::path_to_params_producer_t::base_type_t
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
Definition: easy_parser_router.hpp:628
restinio::router::easy_parser_router::impl::path_to_tuple_producer_t
An implementation of a producer for path_to_tuple case.
Definition: easy_parser_router.hpp:544
restinio::router::easy_parser_router::impl::path_to_tuple_producer_t::base_type_t
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
Definition: easy_parser_router.hpp:545
restinio::router::easy_parser_router::impl::path_to_tuple_producer_t::invoke_handler
static RESTINIO_NODISCARD auto invoke_handler(const generic_request_handle_t< Extra_Data > &req, Handler &&handler, typename base_type_t::result_type &type)
Definition: easy_parser_router.hpp:553
restinio::router::easy_parser_router::impl::router_entry_t
An interface for one entry of easy_parser-based router.
Definition: easy_parser_router.hpp:56
restinio::router::easy_parser_router::impl::router_entry_t::try_handle
virtual RESTINIO_NODISCARD 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.
restinio::router::easy_parser_router::impl::router_entry_t::~router_entry_t
virtual ~router_entry_t()=default
restinio::router::easy_parser_router::impl::router_entry_t::actual_request_handle_t
generic_request_handle_t< Extra_Data > actual_request_handle_t
Definition: easy_parser_router.hpp:58
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t
A special clause type for case when exact_fixed_size_fragment_producer should be used without storing...
Definition: easy_parser_router.hpp:240
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t::producer_t
ep::impl::exact_fixed_size_fragment_producer_t< Size > producer_t
Definition: easy_parser_router.hpp:241
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t::base_type_t
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
Definition: easy_parser_router.hpp:246
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t::consumer_t
ep::impl::any_value_skipper_t consumer_t
Definition: easy_parser_router.hpp:242
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t::special_exact_fixed_size_fragment_clause_t
special_exact_fixed_size_fragment_clause_t(const char(&fragment)[Size])
Definition: easy_parser_router.hpp:249
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t
A special clause type for case when exact_fragment_producer should be used without storing its value.
Definition: easy_parser_router.hpp:272
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::special_exact_fragment_clause_t
special_exact_fragment_clause_t(string_view_t value)
Definition: easy_parser_router.hpp:285
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::consumer_t
ep::impl::any_value_skipper_t consumer_t
Definition: easy_parser_router.hpp:274
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::base_type_t
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
Definition: easy_parser_router.hpp:278
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::special_exact_fragment_clause_t
special_exact_fragment_clause_t(std::string value)
Definition: easy_parser_router.hpp:281
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::producer_t
ep::impl::exact_fragment_producer_t producer_t
Definition: easy_parser_router.hpp:273
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t
A special case of produce-consume clause where the produced value is stored into a tuple.
Definition: easy_parser_router.hpp:197
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t::consumer_t
ep::impl::tuple_item_consumer_t< Index > consumer_t
Definition: easy_parser_router.hpp:198
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t::make_producer
static RESTINIO_NODISCARD Producer make_producer(Producer_Arg &&producer)
Definition: easy_parser_router.hpp:208
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t::base_type_t
ep::impl::consume_value_clause_t< Producer, consumer_t > base_type_t
Definition: easy_parser_router.hpp:202
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t::special_produce_tuple_item_clause_t
special_produce_tuple_item_clause_t(Producer_Arg &&producer)
Definition: easy_parser_router.hpp:215
restinio::router::generic_easy_parser_router_t
A generic request router that uses easy_parser for matching requests with handlers.
Definition: easy_parser_router.hpp:950
restinio::router::generic_easy_parser_router_t::add_handler
void add_handler(Method_Matcher &&method_matcher, Route_Producer &&route, Handler &&handler)
Definition: easy_parser_router.hpp:1004
restinio::router::generic_easy_parser_router_t::extra_data_t
typename Extra_Data_Factory::data_t extra_data_t
Definition: easy_parser_router.hpp:951
restinio::router::generic_easy_parser_router_t::actual_request_handle_t
generic_request_handle_t< extra_data_t > actual_request_handle_t
Definition: easy_parser_router.hpp:954
restinio::router::generic_easy_parser_router_t::operator=
generic_easy_parser_router_t & operator=(generic_easy_parser_router_t &&)=default
restinio::router::generic_easy_parser_router_t::http_get
void http_get(Route_Producer &&route, Handler &&handler)
Set handler for HTTP GET request.
Definition: easy_parser_router.hpp:1028
restinio::router::generic_easy_parser_router_t::http_head
void http_head(Route_Producer &&route, Handler &&handler)
Set handler for HTTP HEAD request.
Definition: easy_parser_router.hpp:1054
restinio::router::generic_easy_parser_router_t::non_matched_request_handler
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.
Definition: easy_parser_router.hpp:1092
restinio::router::generic_easy_parser_router_t::operator=
generic_easy_parser_router_t & operator=(const generic_easy_parser_router_t &)=delete
restinio::router::generic_easy_parser_router_t::m_non_matched_request_handler
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.
Definition: easy_parser_router.hpp:1107
restinio::router::generic_easy_parser_router_t::http_delete
void http_delete(Route_Producer &&route, Handler &&handler)
Set handler for HTTP DELETE request.
Definition: easy_parser_router.hpp:1041
restinio::router::generic_easy_parser_router_t::generic_easy_parser_router_t
generic_easy_parser_router_t(generic_easy_parser_router_t &&)=default
restinio::router::generic_easy_parser_router_t::generic_easy_parser_router_t
generic_easy_parser_router_t()=default
restinio::router::generic_easy_parser_router_t::entries_container_t
std::vector< easy_parser_router::impl::router_entry_unique_ptr_t< extra_data_t > > entries_container_t
Definition: easy_parser_router.hpp:1101
restinio::router::generic_easy_parser_router_t::http_post
void http_post(Route_Producer &&route, Handler &&handler)
Set handler for HTTP POST request.
Definition: easy_parser_router.hpp:1067
restinio::router::generic_easy_parser_router_t::m_entries
entries_container_t m_entries
Definition: easy_parser_router.hpp:1103
restinio::router::generic_easy_parser_router_t::generic_easy_parser_router_t
generic_easy_parser_router_t(const generic_easy_parser_router_t &)=delete
restinio::router::generic_easy_parser_router_t::http_put
void http_put(Route_Producer &&route, Handler &&handler)
Set handler for HTTP PUT request.
Definition: easy_parser_router.hpp:1080
restinio::router::generic_easy_parser_router_t::operator()
RESTINIO_NODISCARD request_handling_status_t operator()(actual_request_handle_t req) const
Definition: easy_parser_router.hpp:969
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::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_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
easy_parser.hpp
An very small, simple and somewhat limited implementation of recursive-descent parser.
method_matcher.hpp
Stuff related to method_matchers.
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:465
restinio::easy_parser
Definition: easy_parser.hpp:39
restinio::easy_parser::any_symbol_if_not_p
RESTINIO_NODISCARD auto any_symbol_if_not_p(char sentinel) noexcept
A factory function to create a any_symbol_if_not_producer.
Definition: easy_parser.hpp:3973
restinio::easy_parser::try_parse
RESTINIO_NODISCARD expected_t< typename Producer::result_type, parse_error_t > try_parse(string_view_t from, Producer producer)
Perform the parsing of the specified content by using specified value producer.
Definition: easy_parser.hpp:5042
restinio::easy_parser::repeat
RESTINIO_NODISCARD auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
Definition: easy_parser.hpp:3876
restinio::easy_parser::N
constexpr std::size_t N
A special marker that means infinite repetitions.
Definition: easy_parser.hpp:455
restinio::easy_parser::to_container
RESTINIO_NODISCARD auto to_container()
A factory function to create a to_container_consumer.
Definition: easy_parser.hpp:4583
restinio::router::easy_parser_router::impl::dsl_details::detect_result_tuple_t
typename detect_result_tuple< Args_Type_List >::type detect_result_tuple_t
Definition: easy_parser_router.hpp:364
restinio::router::easy_parser_router::impl::dsl_details::make_clauses_types_t
typename make_clauses_types< Args_Type_List >::type make_clauses_types_t
Definition: easy_parser_router.hpp:464
restinio::router::easy_parser_router::impl::path_to_params_details::call_with_tuple_impl
decltype(auto) call_with_tuple_impl(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &&params, std::index_sequence< Indexes... >)
Definition: easy_parser_router.hpp:571
restinio::router::easy_parser_router::impl::path_to_params_details::call_with_tuple
decltype(auto) call_with_tuple(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &&params)
A helper function to call a request-handler with a tuple.
Definition: easy_parser_router.hpp:594
restinio::router::easy_parser_router::impl::router_entry_unique_ptr_t
std::unique_ptr< router_entry_t< Extra_Data > > router_entry_unique_ptr_t
An alias for unique_ptr of router_entry.
Definition: easy_parser_router.hpp:87
restinio::router::easy_parser_router::impl::target_path_holder_t
restinio::router::impl::target_path_holder_t target_path_holder_t
Definition: easy_parser_router.hpp:37
restinio::router::easy_parser_router::path_to_params
RESTINIO_NODISCARD 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...
Definition: easy_parser_router.hpp:748
restinio::router::easy_parser_router::path_fragment_p
RESTINIO_NODISCARD auto path_fragment_p(char separator='/')
A factory that creates a string-producer that extracts a sequence on symbols until the separator will...
Definition: easy_parser_router.hpp:805
restinio::router::easy_parser_router::unescape
RESTINIO_NODISCARD auto unescape()
A factory for unescape_transformer.
Definition: easy_parser_router.hpp:862
restinio::router::easy_parser_router::path_to_tuple
RESTINIO_NODISCARD auto path_to_tuple(Args &&...args)
Describe a route for a handler that accepts params from the route in form of a tuple.
Definition: easy_parser_router.hpp:694
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::utils::metaprogramming
Definition: metaprogramming.hpp:24
restinio::utils::metaprogramming::tail_of_t
typename impl::tail_of< L... >::type tail_of_t
Metafunction to get the tail of a list of types in a form of type_list.
Definition: metaprogramming.hpp:129
restinio::utils::metaprogramming::rename_t
typename impl::rename< From, To >::type rename_t
Allows to pass all template arguments from one type to another.
Definition: metaprogramming.hpp:203
restinio::utils::metaprogramming::head_of_t
typename impl::head_of< L... >::type head_of_t
Metafunction to get the first item from a list of types.
Definition: metaprogramming.hpp:91
restinio::utils::metaprogramming::transform_t
typename impl::transform< Transform_F, From, type_list<> >::type transform_t
Applies a specified meta-function to every item from a specified type-list and return a new type-list...
Definition: metaprogramming.hpp:263
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:447
restinio::request_handling_status_t
request_handling_status_t
Request handling status.
Definition: common_types.hpp:26
restinio::expected_t
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
std
STL namespace.
non_matched_request_handler.hpp
The definition of the non_matched_request_handler type.
restinio::easy_parser::impl::transformer_tag
A special base class to be used with transformers.
Definition: easy_parser.hpp:999
restinio::easy_parser::impl::transformer_tag< std::string >::result_type
std::string result_type
Definition: easy_parser.hpp:1000
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary_impl< H, To< Results... >, true >::type
To< Results..., typename H::result_type > type
Definition: easy_parser_router.hpp:314
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary_impl< H, To< Results... >, false >::type
To< Results... > type
Definition: easy_parser_router.hpp:305
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary_impl
Definition: easy_parser_router.hpp:297
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary
Definition: easy_parser_router.hpp:321
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker< From< Sources... >, To< Results... >, Current_Index >::head_type
meta::head_of_t< Sources... > head_type
Definition: easy_parser_router.hpp:426
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker< From< Sources... >, To< Results... >, Current_Index >::type
typename clauses_type_maker< meta::tail_of_t< Sources... >, To< Results..., typename one_clause_type::clause_type >, one_clause_type::next_index >::type type
Definition: easy_parser_router.hpp:437
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker< From<>, To< Results... >, Current_Index >::type
To< Results... > type
Definition: easy_parser_router.hpp:447
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker
Definition: easy_parser_router.hpp:415
restinio::router::easy_parser_router::impl::dsl_details::detect_result_tuple
Definition: easy_parser_router.hpp:355
restinio::router::easy_parser_router::impl::dsl_details::detect_result_tuple::type
meta::rename_t< typename result_tuple_detector< Args_Type_List, meta::type_list<> >::type, std::tuple > type
Definition: easy_parser_router.hpp:360
restinio::router::easy_parser_router::impl::dsl_details::make_clauses_types
Definition: easy_parser_router.hpp:454
restinio::router::easy_parser_router::impl::dsl_details::make_clauses_types::type
meta::rename_t< typename clauses_type_maker< Args_Type_List, meta::type_list<>, 0u >::type, std::tuple > type
Definition: easy_parser_router.hpp:460
restinio::router::easy_parser_router::impl::dsl_details::one_clause_type_processor
Definition: easy_parser_router.hpp:377
restinio::router::easy_parser_router::impl::dsl_details::one_clause_type_processor::clause_type
T clause_type
Definition: easy_parser_router.hpp:378
restinio::router::easy_parser_router::impl::dsl_details::one_clause_type_processor::next_index
static constexpr std::size_t next_index
Definition: easy_parser_router.hpp:379
restinio::router::easy_parser_router::impl::dsl_details::result_tuple_detector< From<>, To< Results... > >::type
To< Results... > type
Definition: easy_parser_router.hpp:349
restinio::router::easy_parser_router::impl::dsl_details::result_tuple_detector< From< Sources... >, To< Results... > >::type
typename result_tuple_detector< meta::tail_of_t< Sources... >, typename add_type_if_necessary< meta::head_of_t< Sources... >, To< Results... > >::type >::type type
Definition: easy_parser_router.hpp:340
restinio::router::easy_parser_router::impl::dsl_details::result_tuple_detector
Definition: easy_parser_router.hpp:325
restinio::router::easy_parser_router::impl::dsl_details::special_decay
A special analog of std::decay meta-function that is handles array differently.
Definition: easy_parser_router.hpp:485
restinio::router::easy_parser_router::impl::dsl_details::special_decay::U
std::remove_reference_t< T > U
Definition: easy_parser_router.hpp:487
restinio::router::easy_parser_router::impl::dsl_details::special_decay::type
typename std::conditional< std::is_array< U >::value, U, std::remove_cv_t< U > >::type type
Definition: easy_parser_router.hpp:494
restinio::router::easy_parser_router::impl::dsl_processor
The main meta-function for processing route DSL.
Definition: easy_parser_router.hpp:517
restinio::router::easy_parser_router::impl::dsl_processor::clauses_tuple
dsl_details::make_clauses_types_t< arg_types > clauses_tuple
Definition: easy_parser_router.hpp:525
restinio::router::easy_parser_router::impl::dsl_processor::result_tuple
dsl_details::detect_result_tuple_t< arg_types > result_tuple
Definition: easy_parser_router.hpp:523
restinio::router::easy_parser_router::impl::dsl_processor::arg_types
meta::transform_t< dsl_details::special_decay, meta::type_list< Args... > > arg_types
Definition: easy_parser_router.hpp:521
restinio::router::easy_parser_router::impl::no_match_t
Helper type to indicate a negative match attempt.
Definition: easy_parser_router.hpp:44
restinio::router::easy_parser_router::impl::unescape_transformer_t
A transformer that performs percent-unescaping of an input string.
Definition: easy_parser_router.hpp:171
restinio::router::easy_parser_router::impl::unescape_transformer_t::input_type
std::string input_type
Definition: easy_parser_router.hpp:172
restinio::router::easy_parser_router::impl::unescape_transformer_t::transform
RESTINIO_NODISCARD result_type transform(input_type &&input) const
Definition: easy_parser_router.hpp:176
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::utils::metaprogramming::type_list
The basic building block: a type for representation of a type list.
Definition: metaprogramming.hpp:54
restinio::utils::restinio_default_unescape_traits
The default traits for escaping and unexcaping symbols in a query string.
Definition: percent_encoding.hpp:36
target_path_holder.hpp
Implementation of target_path_holder helper class.
const
#define const
Definition: zconf.h:230