2
3
6
7
8
9
10
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>
40
41
42
43
47
48
49
50
51
52
53
54template<
typename Extra_Data >
64
65
66
67
68
69
73 const actual_request_handle_t & req,
78
79
80
81
82
83
84
93
94
95
96
97
98
99
100
101
102
103
104
105template<
typename Extra_Data,
typename Producer,
typename Handler >
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 )
129 :
m_producer{ std::forward<Producer_Arg>(producer) }
130 ,
m_handler{ std::forward<Handler_Arg>(handler) }
132 assign( m_method_matcher, std::forward<Method_Matcher>(method_matcher) );
141 if( m_method_matcher->match( req->header().method() ) )
148 return Producer::invoke_handler( req,
m_handler, *parse_result );
160
161
162
163
164
165template<
typename Unescape_Traits >
175 return restinio::
utils::unescape_percent_encoding< Unescape_Traits >(
184
185
186
187
188
189template<
typename Producer, std::size_t Index >
202 template<
typename Producer_Arg >
207 return { std::forward<Producer_Arg>(producer) };
211 template<
typename Producer_Arg >
214 make_producer( std::forward<Producer_Arg>(producer) ),
223
224
225
226
227
228
229
230
231
232template< std::size_t Size >
247 const char (&fragment)[Size] )
256
257
258
259
260
261
262
263
264
293template<
typename H,
typename R,
bool Is_Producer >
298 template<
class...>
class To,
299 typename... Results >
307 template<
class...>
class To,
308 typename... Results >
315template<
typename H,
typename R >
321template<
typename From,
typename To >
326 template<
class...>
class From,
328 template<
class...>
class To,
329 typename... Results >
341 template<
class...>
class From,
342 template<
class...>
class To,
343 typename... Results >
350template<
typename Args_Type_List >
360template<
typename Args_Type_List >
372template<
typename T,
bool Is_Producer, std::size_t Current_Index >
379template< std::size_t Size, std::size_t Current_Index >
386template< std::size_t Current_Index >
400template<
typename T, std::size_t Current_Index >
404 static constexpr std::size_t
next_index = Current_Index + 1u;
411template<
typename From,
typename To, std::size_t Current_Index >
415 template<
class...>
class From,
417 template<
class...>
class To,
419 std::size_t Current_Index >
438 template<
class...>
class From,
439 template<
class...>
class To,
441 std::size_t Current_Index >
449template<
typename Args_Type_List >
460template<
typename Args_Type_List >
467
468
469
470
471
472
473
474
475
476
477
478
479
480template<
typename T >
500
501
502
503
504
505
506
507
508
509
510
511
512template<
typename... Args >
515 static_assert( 0u !=
sizeof...(Args),
"Args can't be an empty list" );
529
530
531
532
533
534
535
537 typename Target_Type,
538 typename Subitems_Tuple >
547 template<
typename Extra_Data,
typename Handler >
551 const generic_request_handle_t< Extra_Data > & req,
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))... );
583
584
585
586
587
588
589template<
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
611
612
613
614
615
616
617
618
620 typename Target_Type,
621 typename Subitems_Tuple >
630 template<
typename User_Type,
typename Handler >
634 const generic_request_handle_t< User_Type > & req,
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688template<
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)... }
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742template<
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)... }
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
804 return produce< std::string >(
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855template<
typename Unescape_Traits =
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945template<
typename Extra_Data_Factory >
971 string_view_t path_to_inspect{ req->header().path() };
972 if( path_to_inspect.size() > 1u &&
'/' == path_to_inspect.back() )
973 path_to_inspect.remove_suffix( 1u );
976 for(
const auto & entry : m_entries )
978 const auto r = entry->try_handle( req, target_path );
986 if( m_non_matched_request_handler )
990 return m_non_matched_request_handler( std::move( req ) );
997 typename Method_Matcher,
998 typename Route_Producer,
1002 Method_Matcher && method_matcher,
1003 Route_Producer && route,
1004 Handler && handler )
1008 using producer_type = std::decay_t< Route_Producer >;
1009 using handler_type = std::decay_t< Handler >;
1011 using actual_entry_type = actual_router_entry_t<
1012 extra_data_t, producer_type, handler_type >;
1014 auto entry = std::make_unique< actual_entry_type >(
1015 std::forward<Method_Matcher>(method_matcher),
1016 std::forward<Route_Producer>(route),
1017 std::forward<Handler>(handler) );
1019 m_entries.push_back( std::move(entry) );
1023 template<
typename Route_Producer,
typename Handler >
1026 Route_Producer && route,
1027 Handler && handler )
1031 std::forward<Route_Producer>(route),
1032 std::forward<Handler>(handler) );
1036 template<
typename Route_Producer,
typename Handler >
1039 Route_Producer && route,
1040 Handler && handler )
1043 http_method_delete(),
1044 std::forward<Route_Producer>(route),
1045 std::forward<Handler>(handler) );
1049 template<
typename Route_Producer,
typename Handler >
1052 Route_Producer && route,
1053 Handler && handler )
1057 std::forward<Route_Producer>(route),
1058 std::forward<Handler>(handler) );
1062 template<
typename Route_Producer,
typename Handler >
1065 Route_Producer && route,
1066 Handler && handler )
1070 std::forward<Route_Producer>(route),
1071 std::forward<Handler>(handler) );
1075 template<
typename Route_Producer,
typename Handler >
1078 Route_Producer && route,
1079 Handler && handler )
1083 std::forward<Route_Producer>(route),
1084 std::forward<Handler>(handler) );
1090 generic_non_matched_request_handler_t< extra_data_t > nmrh )
1092 m_non_matched_request_handler= std::move( nmrh );
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
A template for a clause that binds a value producer with value consumer.
A producer that expects a fragment in the input and produces boolean value if that fragment is found.
A producer that expects a fragment in the input and produces boolean value if that fragment is found.
A template for producing a value of specific type of a sequence of entities from the input stream.
An actual implementation of router_entry interface.
Producer m_producer
Parser of a route and producer of argument(s) for request handler.
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.
actual_router_entry_t(Method_Matcher &&method_matcher, Producer_Arg &&producer, Handler_Arg &&handler)
typename router_entry_t< Extra_Data >::actual_request_handle_t actual_request_handle_t
Handler m_handler
Request handler to be used.
restinio::router::impl::buffered_matcher_holder_t m_method_matcher
HTTP method to match.
An implementation of a producer for path_to_params case.
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
static auto invoke_handler(const generic_request_handle_t< User_Type > &req, Handler &&handler, typename base_type_t::result_type &type)
An implementation of a producer for path_to_tuple case.
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
static auto invoke_handler(const generic_request_handle_t< Extra_Data > &req, Handler &&handler, typename base_type_t::result_type &type)
An interface for one entry of easy_parser-based router.
virtual ~router_entry_t()=default
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.
A special clause type for case when exact_fixed_size_fragment_producer should be used without storing...
ep::impl::exact_fixed_size_fragment_producer_t< Size > producer_t
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
ep::impl::any_value_skipper_t consumer_t
special_exact_fixed_size_fragment_clause_t(const char(&fragment)[Size])
A special clause type for case when exact_fragment_producer should be used without storing its value.
special_exact_fragment_clause_t(string_view_t value)
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
ep::impl::any_value_skipper_t consumer_t
special_exact_fragment_clause_t(std::string value)
ep::impl::exact_fragment_producer_t producer_t
A special case of produce-consume clause where the produced value is stored into a tuple.
static Producer make_producer(Producer_Arg &&producer)
ep::impl::tuple_item_consumer_t< Index > consumer_t
ep::impl::consume_value_clause_t< Producer, consumer_t > base_type_t
special_produce_tuple_item_clause_t(Producer_Arg &&producer)
A generic request router that uses easy_parser for matching requests with handlers.
void add_handler(Method_Matcher &&method_matcher, Route_Producer &&route, Handler &&handler)
typename Extra_Data_Factory::data_t extra_data_t
generic_easy_parser_router_t & operator=(generic_easy_parser_router_t &&)=default
void http_get(Route_Producer &&route, Handler &&handler)
Set handler for HTTP GET request.
void http_head(Route_Producer &&route, Handler &&handler)
Set handler for HTTP HEAD request.
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.
generic_easy_parser_router_t & operator=(const generic_easy_parser_router_t &)=delete
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.
void http_delete(Route_Producer &&route, Handler &&handler)
Set handler for HTTP DELETE request.
request_handling_status_t operator()(actual_request_handle_t req) const
generic_easy_parser_router_t(generic_easy_parser_router_t &&)=default
generic_easy_parser_router_t()=default
void http_post(Route_Producer &&route, Handler &&handler)
Set handler for HTTP POST request.
entries_container_t m_entries
generic_easy_parser_router_t(const generic_easy_parser_router_t &)=delete
void http_put(Route_Producer &&route, Handler &&handler)
Set handler for HTTP PUT request.
A special class that allows to hold a copy of small-size method_matchers or a pointer to dynamically ...
Helper class for holding a unique instance of char array with target_path value.
auto to_container()
A factory function to create a to_container_consumer.
auto any_symbol_if_not_p(char sentinel) noexcept
A factory function to create a any_symbol_if_not_producer.
constexpr std::size_t N
A special marker that means infinite repetitions.
typename detect_result_tuple< Args_Type_List >::type detect_result_tuple_t
typename make_clauses_types< Args_Type_List >::type make_clauses_types_t
decltype(auto) call_with_tuple_impl(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &¶ms, std::index_sequence< Indexes... >)
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.
restinio::router::impl::target_path_holder_t target_path_holder_t
auto path_to_tuple(Args &&...args)
Describe a route for a handler that accepts params from the route in form of a tuple.
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...
auto path_fragment_p(char separator='/')
A factory that creates a string-producer that extracts a sequence on symbols until the separator will...
auto unescape()
A factory for unescape_transformer.
generic_easy_parser_router_t< no_extra_data_factory_t > easy_parser_router_t
A request router that uses easy_parser for matching requests with handlers.
constexpr request_handling_status_t request_not_handled() noexcept
request_handling_status_t
Request handling status.
A special consumer that simply throws any value away.
A consumer that stores a result value at the specified index in the result tuple.
To< Results..., typename H::result_type > type
special_produce_tuple_item_clause_t< T, Current_Index > clause_type
static constexpr std::size_t next_index
static constexpr std::size_t next_index
special_exact_fixed_size_fragment_clause_t< Size > clause_type
static constexpr std::size_t next_index
special_exact_fragment_clause_t clause_type
static constexpr std::size_t next_index
A special analog of std::decay meta-function that is handles array differently.
The main meta-function for processing route DSL.
Helper type to indicate a negative match attempt.
The default traits for escaping and unexcaping symbols in a query string.