Seafire-Routing/seafire/routing/routing-table.cxx

46 lines
940 B
C++
Raw Permalink Normal View History

2025-03-07 02:25:54 +01:00
#include <seafire/routing/routing-table.hxx>
2025-03-07 22:13:09 +01:00
#include <seafire/routing/match.hxx>
2025-03-07 02:25:54 +01:00
namespace seafire::routing
{
routing_table_t::
routing_table_t(std::vector<endpoint_t> endpoints)
: endpoints_{std::move(endpoints)}
{}
std::vector<endpoint_t> const&
routing_table_t::
endpoints() const
{
return endpoints_;
}
std::optional<routing_table_t::find_result_t>
routing_table_t::
2025-03-07 22:13:09 +01:00
find_route(std::string const& host, std::string const& path) const
2025-03-07 02:25:54 +01:00
{
for (auto const& e : endpoints()) {
2025-03-07 22:13:09 +01:00
host_parameters_t host_params;
2025-03-07 02:25:54 +01:00
2025-03-07 22:13:09 +01:00
if (!match(host, e.host(), '.', host_params)) {
continue;
}
2025-03-07 02:25:54 +01:00
2025-03-07 22:13:09 +01:00
route_parameters_t route_params;
2025-03-07 02:25:54 +01:00
2025-03-07 22:13:09 +01:00
if (match(path, e.path(), '/', route_params)) {
return find_result_t{
std::move(host_params),
std::move(route_params),
e.handler()
};
}
2025-03-07 02:25:54 +01:00
}
2025-03-07 22:13:09 +01:00
return std::nullopt;
2025-03-07 02:25:54 +01:00
}
} // namespace seafire::routing