summaryrefslogtreecommitdiffstats
path: root/server/src/http/core/server.cppm
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/http/core/server.cppm')
-rw-r--r--server/src/http/core/server.cppm42
1 files changed, 21 insertions, 21 deletions
diff --git a/server/src/http/core/server.cppm b/server/src/http/core/server.cppm
index dbef975..19eb1c4 100644
--- a/server/src/http/core/server.cppm
+++ b/server/src/http/core/server.cppm
@@ -146,17 +146,17 @@ public:
146}; 146};
147static_assert(beast::concepts::buffers_generator<presponse>); 147static_assert(beast::concepts::buffers_generator<presponse>);
148 148
149template <class Ctx> 149template <typename Ctx>
150using next_handler_t = std::function<auto(Ctx)->net::awaitable<presponse>>; 150using next_handler_t = std::function<auto(Ctx)->net::awaitable<presponse>>;
151 151
152template <class OuterCtx, class InnerCtx> 152template <typename OuterCtx, typename InnerCtx>
153using middleware_t = 153using middleware_t =
154 std::function<auto( 154 std::function<auto(
155 OuterCtx, bhttp::request_header<bhttp::fields>&, 155 OuterCtx, bhttp::request_header<bhttp::fields>&,
156 next_handler_t<InnerCtx>) 156 next_handler_t<InnerCtx>)
157 ->net::awaitable<presponse>>; 157 ->net::awaitable<presponse>>;
158 158
159template <class Ctx> 159template <typename Ctx>
160auto id_middleware( 160auto id_middleware(
161 Ctx ctx, bhttp::request_header<bhttp::fields>&, next_handler_t<Ctx> next) 161 Ctx ctx, bhttp::request_header<bhttp::fields>&, next_handler_t<Ctx> next)
162 -> net::awaitable<presponse> 162 -> net::awaitable<presponse>
@@ -170,14 +170,14 @@ struct base_ctx
170 trace::id trace_id; 170 trace::id trace_id;
171}; 171};
172 172
173template <class Ctx> 173template <typename Ctx>
174using basic_route_handler_fn_t = 174using basic_route_handler_fn_t =
175 std::function<auto( 175 std::function<auto(
176 Ctx, readable_request, 176 Ctx, readable_request,
177 std::vector<std::string> const& matches) 177 std::vector<std::string> const& matches)
178 ->net::awaitable<presponse>>; 178 ->net::awaitable<presponse>>;
179 179
180template <class Ctx> 180template <typename Ctx>
181auto cors_middleware(std::vector<std::string> const& allow_origins) 181auto cors_middleware(std::vector<std::string> const& allow_origins)
182 -> middleware_t<Ctx, Ctx> 182 -> middleware_t<Ctx, Ctx>
183{ 183{
@@ -199,7 +199,7 @@ auto cors_middleware(std::vector<std::string> const& allow_origins)
199 }; 199 };
200} 200}
201 201
202template <class Ctx> 202template <typename Ctx>
203auto expose_trace_id_middleware( 203auto expose_trace_id_middleware(
204 Ctx ctx, bhttp::request_header<bhttp::fields>& req_hdr, 204 Ctx ctx, bhttp::request_header<bhttp::fields>& req_hdr,
205 next_handler_t<Ctx> next) -> net::awaitable<presponse> 205 next_handler_t<Ctx> next) -> net::awaitable<presponse>
@@ -214,7 +214,7 @@ auto expose_trace_id_middleware(
214 co_return std::move(prersp); 214 co_return std::move(prersp);
215} 215}
216 216
217template <class Ctx> 217template <typename Ctx>
218auto expose_content_language_middleware( 218auto expose_content_language_middleware(
219 Ctx ctx, bhttp::request_header<bhttp::fields>& req_hdr, 219 Ctx ctx, bhttp::request_header<bhttp::fields>& req_hdr,
220 next_handler_t<Ctx> next) -> net::awaitable<presponse> 220 next_handler_t<Ctx> next) -> net::awaitable<presponse>
@@ -297,17 +297,17 @@ auto read_empty_request(base_ctx const& ctx, readable_request&& r) -> net::
297 co_return r.p->release(); 297 co_return r.p->release();
298} 298}
299 299
300template <class InnerCtx> 300template <typename InnerCtx>
301struct routed_ctx : InnerCtx 301struct routed_ctx : InnerCtx
302{ 302{
303 verb_set route_methods; 303 verb_set route_methods;
304 boost::urls::url target; 304 boost::urls::url target;
305}; 305};
306 306
307template <class Ctx> 307template <typename Ctx>
308 requires requires(Ctx ctx) { 308 requires requires(Ctx ctx) {
309 // Ctx must be derived from an instantiation of routed_ctx 309 // Ctx must be derived from an instantiation of routed_ctx
310 []<class InnerCtx>(routed_ctx<InnerCtx> const&) {}(ctx); 310 []<typename InnerCtx>(routed_ctx<InnerCtx> const&) {}(ctx);
311 } 311 }
312auto default_options_handler( 312auto default_options_handler(
313 Ctx const& ctx, readable_request r, std::vector<std::string> const&) 313 Ctx const& ctx, readable_request r, std::vector<std::string> const&)
@@ -343,7 +343,7 @@ auto default_options_handler(
343auto global_options_handler(base_ctx const& ctx, readable_request r) 343auto global_options_handler(base_ctx const& ctx, readable_request r)
344 -> net::awaitable<presponse>; 344 -> net::awaitable<presponse>;
345 345
346template <class A, class B, class C> 346template <typename A, typename B, typename C>
347auto middleware_compose(middleware_t<A, B> ab, middleware_t<B, C> bc) 347auto middleware_compose(middleware_t<A, B> ab, middleware_t<B, C> bc)
348 -> middleware_t<A, C> 348 -> middleware_t<A, C>
349{ 349{
@@ -357,7 +357,7 @@ auto middleware_compose(middleware_t<A, B> ab, middleware_t<B, C> bc)
357 }; 357 };
358} 358}
359 359
360template <class A, class B> 360template <typename A, typename B>
361auto middleware_wrap_fn(middleware_t<A, B> ab, basic_route_handler_fn_t<B> fn) 361auto middleware_wrap_fn(middleware_t<A, B> ab, basic_route_handler_fn_t<B> fn)
362 -> basic_route_handler_fn_t<A> 362 -> basic_route_handler_fn_t<A>
363{ 363{
@@ -386,7 +386,7 @@ struct handler_map
386 V post = {}; 386 V post = {};
387 V put = {}; 387 V put = {};
388 388
389 template <class Self> 389 template <typename Self>
390 auto lookup(this Self&& self, supported_verb v) -> auto&& 390 auto lookup(this Self&& self, supported_verb v) -> auto&&
391 { 391 {
392 switch (v.value) 392 switch (v.value)
@@ -436,7 +436,7 @@ struct handler_map
436 } 436 }
437}; 437};
438 438
439template <class Ctx> 439template <typename Ctx>
440struct route_tree 440struct route_tree
441{ 441{
442 using leaves = handler_map<basic_route_handler_fn_t<Ctx>>; 442 using leaves = handler_map<basic_route_handler_fn_t<Ctx>>;
@@ -451,7 +451,7 @@ struct route_tree
451 std::variant<named_subtrees, wildcard_subtree> sub; 451 std::variant<named_subtrees, wildcard_subtree> sub;
452}; 452};
453 453
454template <class OuterCtx, class InnerCtx> 454template <typename OuterCtx, typename InnerCtx>
455auto middleware_wrap_tree( 455auto middleware_wrap_tree(
456 middleware_t<OuterCtx, InnerCtx> mw, route_tree<InnerCtx> const& tree) 456 middleware_t<OuterCtx, InnerCtx> mw, route_tree<InnerCtx> const& tree)
457 -> route_tree<OuterCtx> 457 -> route_tree<OuterCtx>
@@ -479,15 +479,15 @@ auto middleware_wrap_tree(
479 return {.here = new_leaves, .sub = new_sub}; 479 return {.here = new_leaves, .sub = new_sub};
480} 480}
481 481
482template <class T> 482template <typename T>
483concept match_arg = std::constructible_from<T, std::string const&>; 483concept match_arg = std::constructible_from<T, std::string const&>;
484 484
485template <class Ctx, match_arg... MatchArgs> 485template <typename Ctx, match_arg... MatchArgs>
486using route_handler_fn_t = 486using route_handler_fn_t =
487 std::function<auto(Ctx, readable_request, MatchArgs...) 487 std::function<auto(Ctx, readable_request, MatchArgs...)
488 ->net::awaitable<presponse>>; 488 ->net::awaitable<presponse>>;
489 489
490template <class Ctx, match_arg... MatchArgs> 490template <typename Ctx, match_arg... MatchArgs>
491auto degen_route_handler(route_handler_fn_t<Ctx, MatchArgs...> fn) 491auto degen_route_handler(route_handler_fn_t<Ctx, MatchArgs...> fn)
492 -> basic_route_handler_fn_t<Ctx> 492 -> basic_route_handler_fn_t<Ctx>
493{ 493{
@@ -505,10 +505,10 @@ auto degen_route_handler(route_handler_fn_t<Ctx, MatchArgs...> fn)
505 }; 505 };
506} 506}
507 507
508template <class Ctx, match_arg... MatchArgs> 508template <typename Ctx, match_arg... MatchArgs>
509struct ctree : route_tree<Ctx> 509struct ctree : route_tree<Ctx>
510{ 510{
511 template <class OuterCtx> 511 template <typename OuterCtx>
512 auto wrap(middleware_t<OuterCtx, Ctx> mw) const 512 auto wrap(middleware_t<OuterCtx, Ctx> mw) const
513 -> ctree<OuterCtx, MatchArgs...> 513 -> ctree<OuterCtx, MatchArgs...>
514 { 514 {
@@ -516,7 +516,7 @@ struct ctree : route_tree<Ctx>
516 } 516 }
517}; 517};
518 518
519template <class Ctx, match_arg... MatchArgs> 519template <typename Ctx, match_arg... MatchArgs>
520struct dtree : handler_map<route_handler_fn_t<Ctx, MatchArgs...>> 520struct dtree : handler_map<route_handler_fn_t<Ctx, MatchArgs...>>
521{ 521{
522 [[nodiscard]] auto to_leaves() const -> typename route_tree<Ctx>::leaves 522 [[nodiscard]] auto to_leaves() const -> typename route_tree<Ctx>::leaves