From 02a7e8f7c64a0cfe85063309c291b2b24c0e254a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Mon, 25 Aug 2025 21:34:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BF=D0=B0=D0=BA=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=20=D0=B8=20Executor'=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/endpoints_handlers/RootExecutor.h | 32 +++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/endpoints_handlers/RootExecutor.h b/src/endpoints_handlers/RootExecutor.h index 8c590ab..5edf9f3 100644 --- a/src/endpoints_handlers/RootExecutor.h +++ b/src/endpoints_handlers/RootExecutor.h @@ -32,15 +32,33 @@ public: boost::beast::http::request>&& req ) override { - boost::beast::http::response res{ - boost::beast::http::status::ok, req.version() - }; + auto const not_found = [&req](boost::beast::string_view target) + { + boost::beast::http::response res{ + boost::beast::http::status::not_found, req.version() + }; + res.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING); + res.set(boost::beast::http::field::content_type, "text/html"); + res.keep_alive(req.keep_alive()); + res.body() = "The resource '" + std::string(target) + "' was not found."; + res.prepare_payload(); + return res; + }; - res.body() = "{ \"detail\": \"ok\"}"; - res.set(boost::beast::http::field::content_type, "application/json"); - res.content_length(res.body().size()); + const std::string& route = req.target(); + const bool is_match_no_route = !routes_pathes_.count(route); - return res; + if (is_match_no_route) return not_found(req.target()); + + std::optional> maybe_executor_ptr = routes_pathes_ + .at(route) + ->FindExecutor(req.method()); + + if (!maybe_executor_ptr.has_value()) return not_found(req.target()); + + IRouteExecutor& executor = *maybe_executor_ptr.value(); + + return executor(std::move(req)); } }; }