generated from Sithas/conan_template
Упаковка контроллеров и Executor'ов
This commit is contained in:
@@ -32,15 +32,33 @@ public:
|
||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||
) override
|
||||
{
|
||||
boost::beast::http::response<ResponseType> res{
|
||||
boost::beast::http::status::ok, req.version()
|
||||
auto const not_found = [&req](boost::beast::string_view target)
|
||||
{
|
||||
boost::beast::http::response<boost::beast::http::string_body> res{
|
||||
boost::beast::http::status::not_found, req.version()
|
||||
};
|
||||
|
||||
res.body() = "{ \"detail\": \"ok\"}";
|
||||
res.set(boost::beast::http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
const std::string& route = req.target();
|
||||
const bool is_match_no_route = !routes_pathes_.count(route);
|
||||
|
||||
if (is_match_no_route) return not_found(req.target());
|
||||
|
||||
std::optional<std::shared_ptr<IRouteExecutor>> 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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user