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
|
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||||
) override
|
) override
|
||||||
{
|
{
|
||||||
boost::beast::http::response<ResponseType> res{
|
auto const not_found = [&req](boost::beast::string_view target)
|
||||||
boost::beast::http::status::ok, req.version()
|
{
|
||||||
};
|
boost::beast::http::response<boost::beast::http::string_body> 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\"}";
|
const std::string& route = req.target();
|
||||||
res.set(boost::beast::http::field::content_type, "application/json");
|
const bool is_match_no_route = !routes_pathes_.count(route);
|
||||||
res.content_length(res.body().size());
|
|
||||||
|
|
||||||
return res;
|
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