717 uint16_t rule_index{};
719 uint16_t blueprint_index{INVALID_BP_ID};
721 ParamType param = ParamType::MAX;
722 std::vector<Node> children;
724 bool IsSimpleNode()
const
726 return !rule_index &&
727 blueprint_index == INVALID_BP_ID &&
728 children.size() < 2 &&
729 param == ParamType::MAX &&
730 std::all_of(std::begin(children), std::end(children), [](
const Node& x) {
731 return x.param == ParamType::MAX;
735 Node& add_child_node()
737 children.emplace_back();
738 return children.back();
749 return head_.children.empty();
754 for (
auto& child : head_.children)
762 void optimizeNode(Node& node)
764 if (node.children.empty())
766 if (node.IsSimpleNode())
768 auto children_temp = std::move(node.children);
769 auto& child_temp = children_temp[0];
770 node.key += child_temp.key;
771 node.rule_index = child_temp.rule_index;
772 node.blueprint_index = child_temp.blueprint_index;
773 node.children = std::move(child_temp.children);
778 for (
auto& child : node.children)
785 void debug_node_print(
const Node& node,
int level)
787 if (node.param != ParamType::MAX)
792 CROW_LOG_DEBUG << std::string(3 * level,
' ') <<
"└➝ "
795 case ParamType::UINT:
796 CROW_LOG_DEBUG << std::string(3 * level,
' ') <<
"└➝ "
799 case ParamType::DOUBLE:
800 CROW_LOG_DEBUG << std::string(3 * level,
' ') <<
"└➝ "
803 case ParamType::STRING:
804 CROW_LOG_DEBUG << std::string(3 * level,
' ') <<
"└➝ "
807 case ParamType::PATH:
808 CROW_LOG_DEBUG << std::string(3 * level,
' ') <<
"└➝ "
812 CROW_LOG_DEBUG << std::string(3 * level,
' ') <<
"└➝ "
818 CROW_LOG_DEBUG << std::string(3 * level,
' ') <<
"└➝ " << node.key;
820 for (
const auto& child : node.children)
822 debug_node_print(child, level + 1);
829 CROW_LOG_DEBUG <<
"└➙ ROOT";
830 for (
const auto& child : head_.children)
831 debug_node_print(child, 1);
836 if (!head_.IsSimpleNode())
837 throw std::runtime_error(
"Internal error: Trie header should be simple!");
842 routing_handle_result find(
const std::string& req_url,
const Node& node,
unsigned pos = 0, routing_params* params =
nullptr, std::vector<uint16_t>* blueprints =
nullptr)
const
845 routing_params empty;
846 if (params ==
nullptr)
849 std::vector<uint16_t> MT;
850 if (blueprints ==
nullptr)
854 std::vector<uint16_t> found_BP;
855 routing_params match_params;
857 auto update_found = [&found, &found_BP, &match_params](routing_handle_result& ret) {
858 found_BP = std::move(ret.blueprint_indices);
859 if (ret.rule_index && (!found || found > ret.rule_index))
861 found = ret.rule_index;
862 match_params = std::move(ret.r_params);
867 if (pos == req_url.size())
869 found_BP = std::move(*blueprints);
870 return routing_handle_result{node.rule_index, *blueprints, *params};
873 bool found_fragment =
false;
875 for (
const auto& child : node.children)
877 if (child.param != ParamType::MAX)
879 if (child.param == ParamType::INT)
881 char c = req_url[pos];
882 if ((c >=
'0' && c <=
'9') || c ==
'+' || c ==
'-')
886 long long int value = strtoll(req_url.data() + pos, &eptr, 10);
887 if (errno != ERANGE && eptr != req_url.data() + pos)
889 found_fragment =
true;
890 params->int_params.push_back(value);
891 if (child.blueprint_index != INVALID_BP_ID) blueprints->push_back(child.blueprint_index);
892 auto ret = find(req_url, child, eptr - req_url.data(), params, blueprints);
894 params->int_params.pop_back();
895 if (!blueprints->empty()) blueprints->pop_back();
900 else if (child.param == ParamType::UINT)
902 char c = req_url[pos];
903 if ((c >=
'0' && c <=
'9') || c ==
'+')
907 unsigned long long int value = strtoull(req_url.data() + pos, &eptr, 10);
908 if (errno != ERANGE && eptr != req_url.data() + pos)
910 found_fragment =
true;
911 params->uint_params.push_back(value);
912 if (child.blueprint_index != INVALID_BP_ID) blueprints->push_back(child.blueprint_index);
913 auto ret = find(req_url, child, eptr - req_url.data(), params, blueprints);
915 params->uint_params.pop_back();
916 if (!blueprints->empty()) blueprints->pop_back();
921 else if (child.param == ParamType::DOUBLE)
923 char c = req_url[pos];
924 if ((c >=
'0' && c <=
'9') || c ==
'+' || c ==
'-' || c ==
'.')
928 double value = strtod(req_url.data() + pos, &eptr);
929 if (errno != ERANGE && eptr != req_url.data() + pos)
931 found_fragment =
true;
932 params->double_params.push_back(value);
933 if (child.blueprint_index != INVALID_BP_ID) blueprints->push_back(child.blueprint_index);
934 auto ret = find(req_url, child, eptr - req_url.data(), params, blueprints);
936 params->double_params.pop_back();
937 if (!blueprints->empty()) blueprints->pop_back();
942 else if (child.param == ParamType::STRING)
945 for (; epos < req_url.size(); epos++)
947 if (req_url[epos] ==
'/')
953 found_fragment =
true;
954 params->string_params.push_back(req_url.substr(pos, epos - pos));
955 if (child.blueprint_index != INVALID_BP_ID) blueprints->push_back(child.blueprint_index);
956 auto ret = find(req_url, child, epos, params, blueprints);
958 params->string_params.pop_back();
959 if (!blueprints->empty()) blueprints->pop_back();
963 else if (child.param == ParamType::PATH)
965 size_t epos = req_url.size();
969 found_fragment =
true;
970 params->string_params.push_back(req_url.substr(pos, epos - pos));
971 if (child.blueprint_index != INVALID_BP_ID) blueprints->push_back(child.blueprint_index);
972 auto ret = find(req_url, child, epos, params, blueprints);
974 params->string_params.pop_back();
975 if (!blueprints->empty()) blueprints->pop_back();
982 const std::string& fragment = child.key;
983 if (req_url.compare(pos, fragment.size(), fragment) == 0)
985 found_fragment =
true;
986 if (child.blueprint_index != INVALID_BP_ID) blueprints->push_back(child.blueprint_index);
987 auto ret = find(req_url, child, pos + fragment.size(), params, blueprints);
989 if (!blueprints->empty()) blueprints->pop_back();
995 found_BP = std::move(*blueprints);
997 return routing_handle_result{found, found_BP, match_params};
1000 routing_handle_result find(
const std::string& req_url)
const
1002 return find(req_url, head_);
1006 void add(
const std::string& url, uint16_t rule_index,
unsigned bp_prefix_length = 0, uint16_t blueprint_index = INVALID_BP_ID)
1010 bool has_blueprint = bp_prefix_length != 0 && blueprint_index != INVALID_BP_ID;
1012 for (
unsigned i = 0; i < url.size(); i++)
1017 static struct ParamTraits
1023 {ParamType::INT,
"<int>"},
1024 {ParamType::UINT,
"<uint>"},
1025 {ParamType::DOUBLE,
"<float>"},
1026 {ParamType::DOUBLE,
"<double>"},
1027 {ParamType::STRING,
"<str>"},
1028 {ParamType::STRING,
"<string>"},
1029 {ParamType::PATH,
"<path>"},
1032 for (
const auto& x : paramTraits)
1034 if (url.compare(i, x.name.size(), x.name) == 0)
1037 for (
auto& child : idx->children)
1039 if (child.param == x.type)
1050 auto new_node_idx = &idx->add_child_node();
1051 new_node_idx->param = x.type;
1063 bool piece_found =
false;
1064 for (
auto& child : idx->children)
1066 if (child.key[0] == c)
1075 auto new_node_idx = &idx->add_child_node();
1076 new_node_idx->key = c;
1078 if (has_blueprint && i == bp_prefix_length)
1079 new_node_idx->blueprint_index = blueprint_index;
1086 if (idx->rule_index)
1087 throw std::runtime_error(
"handler already exists for " + url);
1088 idx->rule_index = rule_index;
1105 static_dir_(prefix),
1106 templates_dir_(prefix){};
1108 Blueprint(
const std::string& prefix,
const std::string& static_dir):
1109 prefix_(prefix), static_dir_(static_dir){};
1111 Blueprint(
const std::string& prefix,
const std::string& static_dir,
const std::string& templates_dir):
1112 prefix_(prefix), static_dir_(static_dir), templates_dir_(templates_dir){};
1129 *
this = std::move(value);
1136 prefix_ = std::move(value.prefix_);
1137 static_dir_ = std::move(value.static_dir_);
1138 templates_dir_ = std::move(value.templates_dir_);
1139 all_rules_ = std::move(value.all_rules_);
1140 catchall_rule_ = std::move(value.catchall_rule_);
1141 blueprints_ = std::move(value.blueprints_);
1142 mw_indices_ = std::move(value.mw_indices_);
1148 return value.prefix() == prefix_;
1153 return value.prefix() != prefix_;
1156 std::string prefix()
const
1161 std::string static_dir()
const
1176 DynamicRule& new_rule_dynamic(
const std::string& rule)
1178 std::string new_rule =
'/' + prefix_ + rule;
1179 auto ruleObject =
new DynamicRule(std::move(new_rule));
1180 ruleObject->custom_templates_base = templates_dir_;
1181 all_rules_.emplace_back(ruleObject);
1186 template<u
int64_t N>
1187 typename black_magic::arguments<N>::type::template rebind<TaggedRule>& new_rule_tagged(
const std::string& rule)
1189 std::string new_rule =
'/' + prefix_ + rule;
1190 using RuleT =
typename black_magic::arguments<N>::type::template rebind<TaggedRule>;
1192 auto ruleObject =
new RuleT(std::move(new_rule));
1193 ruleObject->custom_templates_base = templates_dir_;
1194 all_rules_.emplace_back(ruleObject);
1199 void register_blueprint(
Blueprint& blueprint)
1201 if (blueprints_.empty() || std::find(blueprints_.begin(), blueprints_.end(), &blueprint) == blueprints_.end())
1203 apply_blueprint(blueprint);
1204 blueprints_.emplace_back(&blueprint);
1207 throw std::runtime_error(
"blueprint \"" + blueprint.prefix_ +
"\" already exists in blueprint \"" + prefix_ +
'\"');
1213 return catchall_rule_;
1216 template<
typename App,
typename... Middlewares>
1219 mw_indices_.push<
App, Middlewares...>();
1223 void apply_blueprint(
Blueprint& blueprint)
1226 blueprint.prefix_ = prefix_ +
'/' + blueprint.prefix_;
1227 blueprint.static_dir_ = static_dir_ +
'/' + blueprint.static_dir_;
1228 blueprint.templates_dir_ = templates_dir_ +
'/' + blueprint.templates_dir_;
1229 for (
auto& rule : blueprint.all_rules_)
1231 std::string new_rule =
'/' + prefix_ + rule->rule_;
1232 rule->rule_ = new_rule;
1234 for (
Blueprint* bp_child : blueprint.blueprints_)
1237 apply_blueprint(bp_ref);
1241 std::string prefix_;
1242 std::string static_dir_;
1243 std::string templates_dir_;
1244 std::vector<std::unique_ptr<BaseRule>> all_rules_;
1246 std::vector<Blueprint*> blueprints_;
1259 Router() : using_ssl(
false)
1262 DynamicRule& new_rule_dynamic(
const std::string& rule)
1265 all_rules_.emplace_back(ruleObject);
1270 template<u
int64_t N>
1271 typename black_magic::arguments<N>::type::template rebind<TaggedRule>& new_rule_tagged(
const std::string& rule)
1273 using RuleT =
typename black_magic::arguments<N>::type::template rebind<TaggedRule>;
1275 auto ruleObject =
new RuleT(rule);
1276 all_rules_.emplace_back(ruleObject);
1283 return catchall_rule_;
1286 void internal_add_rule_object(
const std::string& rule,
BaseRule* ruleObject)
1288 internal_add_rule_object(rule, ruleObject, INVALID_BP_ID, blueprints_);
1291 void internal_add_rule_object(
const std::string& rule,
BaseRule* ruleObject,
const uint16_t& BP_index, std::vector<Blueprint*>& blueprints)
1293 bool has_trailing_slash =
false;
1294 std::string rule_without_trailing_slash;
1295 if (rule.size() > 1 && rule.back() ==
'/')
1297 has_trailing_slash =
true;
1298 rule_without_trailing_slash = rule;
1299 rule_without_trailing_slash.pop_back();
1302 ruleObject->mw_indices_.pack();
1304 ruleObject->foreach_method([&](
int method) {
1305 per_methods_[method].rules.emplace_back(ruleObject);
1306 per_methods_[method].trie.add(rule, per_methods_[method].rules.size() - 1, BP_index != INVALID_BP_ID ? blueprints[BP_index]->prefix().length() : 0, BP_index);
1310 if (has_trailing_slash)
1312 per_methods_[method].trie.add(rule_without_trailing_slash, RULE_SPECIAL_REDIRECT_SLASH, BP_index != INVALID_BP_ID ? blueprints[BP_index]->prefix().length() : 0, BP_index);
1316 ruleObject->set_added();
1319 void register_blueprint(
Blueprint& blueprint)
1321 if (std::find(blueprints_.begin(), blueprints_.end(), &blueprint) == blueprints_.end())
1323 blueprints_.emplace_back(&blueprint);
1326 throw std::runtime_error(
"blueprint \"" + blueprint.prefix_ +
"\" already exists in router");
1329 void get_recursive_child_methods(
Blueprint* blueprint, std::vector<HTTPMethod>& methods)
1332 if (blueprint->static_dir_.empty() && blueprint->all_rules_.empty())
1334 for (
Blueprint* bp : blueprint->blueprints_)
1336 get_recursive_child_methods(bp, methods);
1339 else if (!blueprint->static_dir_.empty())
1340 methods.emplace_back(HTTPMethod::Get);
1341 for (
auto& rule : blueprint->all_rules_)
1343 rule->foreach_method([&methods](
unsigned method) {
1344 HTTPMethod method_final =
static_cast<HTTPMethod
>(method);
1345 if (std::find(methods.begin(), methods.end(), method_final) == methods.end())
1346 methods.emplace_back(method_final);
1355 validate_bp(blueprints_, blueprint_mw);
1360 for (
unsigned i = 0; i < blueprints.size(); i++)
1364 if (blueprint->is_added())
continue;
1366 if (blueprint->static_dir_ ==
"" && blueprint->all_rules_.empty())
1368 std::vector<HTTPMethod> methods;
1369 get_recursive_child_methods(blueprint, methods);
1370 for (HTTPMethod x : methods)
1372 int method_index =
static_cast<int>(x);
1373 per_methods_[method_index].trie.add(blueprint->prefix(), 0, blueprint->prefix().length(), method_index);
1377 current_mw.merge_back(blueprint->mw_indices_);
1378 for (
auto& rule : blueprint->all_rules_)
1380 if (rule && !rule->is_added())
1382 auto upgraded = rule->upgrade();
1384 rule = std::move(upgraded);
1386 rule->mw_indices_.merge_front(current_mw);
1387 internal_add_rule_object(rule->rule(), rule.get(), i, blueprints);
1390 validate_bp(blueprint->blueprints_, current_mw);
1391 current_mw.pop_back(blueprint->mw_indices_);
1392 blueprint->set_added();
1398 for (
auto& rule : all_rules_)
1400 if (rule && !rule->is_added())
1402 auto upgraded = rule->upgrade();
1404 rule = std::move(upgraded);
1406 internal_add_rule_object(rule->rule(), rule.get());
1409 for (
auto& per_method : per_methods_)
1411 per_method.trie.validate();
1416 template<
typename Adaptor>
1417 void handle_upgrade(
const request& req,
response& res, Adaptor&& adaptor)
1419 if (req.method >= HTTPMethod::InternalMethodCount)
1422 auto& per_method = per_methods_[
static_cast<int>(req.method)];
1423 auto& rules = per_method.rules;
1424 unsigned rule_index = per_method.trie.find(req.
url).rule_index;
1428 for (
auto& method : per_methods_)
1430 if (method.trie.find(req.
url).rule_index)
1432 CROW_LOG_DEBUG <<
"Cannot match method " << req.
url <<
" " << method_name(req.method);
1439 CROW_LOG_INFO <<
"Cannot match rules " << req.
url;
1445 if (rule_index >= rules.size())
1446 throw std::runtime_error(
"Trie internal structure corrupted!");
1448 if (rule_index == RULE_SPECIAL_REDIRECT_SLASH)
1450 CROW_LOG_INFO <<
"Redirecting to a url with trailing slash: " << req.
url;
1457 CROW_LOG_DEBUG <<
"Matched rule (upgrade) '" << rules[rule_index]->rule_ <<
"' " <<
static_cast<uint32_t
>(req.method) <<
" / " << rules[rule_index]->get_methods();
1461 rules[rule_index]->handle_upgrade(req, res, std::move(adaptor));
1465 exception_handler_(res);
1471 void get_found_bp(std::vector<uint16_t>& bp_i, std::vector<Blueprint*>& blueprints, std::vector<Blueprint*>& found_bps, uint16_t index = 0)
1481 auto verify_prefix = [&bp_i, &index, &blueprints, &found_bps]() {
1483 bp_i[index] < blueprints.size() &&
1484 blueprints[bp_i[index]]->prefix().substr(0, found_bps[index - 1]->prefix().length() + 1).compare(std::string(found_bps[index - 1]->prefix() +
'/')) == 0;
1486 if (index < bp_i.size())
1489 if (verify_prefix())
1491 found_bps.push_back(blueprints[bp_i[index]]);
1492 get_found_bp(bp_i, found_bps.back()->blueprints_, found_bps, ++index);
1496 if (found_bps.size() < 2)
1499 found_bps.push_back(blueprints_[bp_i[index]]);
1503 found_bps.pop_back();
1504 Blueprint* last_element = found_bps.back();
1505 found_bps.push_back(last_element->blueprints_[bp_i[index]]);
1507 get_found_bp(bp_i, found_bps.back()->blueprints_, found_bps, ++index);
1516 std::vector<Blueprint*> bps_found;
1517 get_found_bp(found.blueprint_indices, blueprints_, bps_found);
1518 for (
int i = bps_found.size() - 1; i > 0; i--)
1520 std::vector<uint16_t> bpi = found.blueprint_indices;
1521 if (bps_found[i]->catchall_rule().has_handler())
1525 bps_found[i]->catchall_rule().handler_(req, res);
1529 exception_handler_(res);
1531#ifdef CROW_ENABLE_DEBUG
1532 return std::string(
"Redirected to Blueprint \"" + bps_found[i]->prefix() +
"\" Catchall rule");
1534 return std::string();
1538 if (catchall_rule_.has_handler())
1542 catchall_rule_.handler_(req, res);
1546 exception_handler_(res);
1548#ifdef CROW_ENABLE_DEBUG
1549 return std::string(
"Redirected to global Catchall rule");
1551 return std::string();
1554 return std::string();
1557 std::unique_ptr<routing_handle_result> handle_initial(
request& req,
response& res)
1559 HTTPMethod method_actual = req.method;
1561 std::unique_ptr<routing_handle_result> found{
1564 std::vector<uint16_t>(),
1566 HTTPMethod::InternalMethodCount)};
1569 if (CROW_UNLIKELY(req.method >= HTTPMethod::InternalMethodCount))
1571 else if (req.method == HTTPMethod::Head)
1573 *found = per_methods_[
static_cast<int>(method_actual)].trie.find(req.
url);
1575 if (!found->rule_index)
1577 method_actual = HTTPMethod::Get;
1578 *found = per_methods_[
static_cast<int>(method_actual)].trie.find(req.
url);
1579 if (!found->rule_index)
1581 CROW_LOG_DEBUG <<
"Cannot match rules " << req.
url;
1582 res = response(404);
1589 found->method = method_actual;
1592 else if (req.method == HTTPMethod::Options)
1594 std::string allow =
"OPTIONS, HEAD";
1596 if (req.
url ==
"/*")
1598 for (
int i = 0; i < static_cast<int>(HTTPMethod::InternalMethodCount); i++)
1600 if (
static_cast<int>(HTTPMethod::Head) == i)
1603 if (!per_methods_[i].trie.is_empty())
1606 allow.append(method_name(
static_cast<HTTPMethod
>(i)));
1609#ifdef CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST
1610 res = response(crow::status::OK);
1612 res = response(crow::status::NO_CONTENT);
1617 found->method = method_actual;
1622 bool rules_matched =
false;
1623 for (
int i = 0; i < static_cast<int>(HTTPMethod::InternalMethodCount); i++)
1625 if (per_methods_[i].trie.find(req.
url).rule_index)
1627 rules_matched =
true;
1629 if (
static_cast<int>(HTTPMethod::Head) == i)
1633 allow.append(method_name(
static_cast<HTTPMethod
>(i)));
1638#ifdef CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST
1639 res = response(crow::status::OK);
1641 res = response(crow::status::NO_CONTENT);
1645 found->method = method_actual;
1650 CROW_LOG_DEBUG <<
"Cannot match rules " << req.
url;
1651 res = response(404);
1659 *found = per_methods_[
static_cast<int>(method_actual)].trie.find(req.
url);
1661 if (!found->rule_index)
1663 for (
auto& per_method : per_methods_)
1665 if (per_method.trie.find(req.
url).rule_index)
1667 const std::string error_message(
get_error(405, *found, req, res));
1668 CROW_LOG_DEBUG <<
"Cannot match method " << req.
url <<
" " << method_name(method_actual) <<
". " << error_message;
1675 const std::string error_message(
get_error(404, *found, req, res));
1676 CROW_LOG_DEBUG <<
"Cannot match rules " << req.
url <<
". " << error_message;
1681 found->method = method_actual;
1686 template<
typename App>
1687 void handle(request& req, response& res, routing_handle_result found)
1689 HTTPMethod method_actual = found.method;
1690 auto& rules = per_methods_[
static_cast<int>(method_actual)].rules;
1691 unsigned rule_index = found.rule_index;
1693 if (rule_index >= rules.size())
1694 throw std::runtime_error(
"Trie internal structure corrupted!");
1696 if (rule_index == RULE_SPECIAL_REDIRECT_SLASH)
1698 CROW_LOG_INFO <<
"Redirecting to a url with trailing slash: " << req.url;
1699 res = response(301);
1700 res.add_header(
"Location", req.url +
"/");
1705 CROW_LOG_DEBUG <<
"Matched rule '" << rules[rule_index]->rule_ <<
"' " <<
static_cast<uint32_t
>(req.method) <<
" / " << rules[rule_index]->get_methods();
1709 BaseRule& rule = *rules[rule_index];
1710 handle_rule<App>(rule, req, res, found.r_params);
1714 exception_handler_(res);
1720 template<
typename App>
1721 typename std::enable_if<std::tuple_size<typename App::mw_container_t>::value != 0,
void>::type
1724 if (!rule.mw_indices_.empty())
1726 auto& ctx = *
reinterpret_cast<typename App::context_t*
>(req.middleware_context);
1727 auto& container = *
reinterpret_cast<typename App::mw_container_t*
>(req.middleware_container);
1728 detail::middleware_call_criteria_dynamic<false> crit_fwd(rule.mw_indices_.indices());
1730 auto glob_completion_handler = std::move(res.complete_request_handler_);
1731 res.complete_request_handler_ = [] {};
1733 detail::middleware_call_helper<
decltype(crit_fwd),
1734 0,
typename App::context_t,
typename App::mw_container_t>(crit_fwd, container, req, res, ctx);
1738 glob_completion_handler();
1742 res.complete_request_handler_ = [&rule, &ctx, &container, &req, &res, glob_completion_handler] {
1743 detail::middleware_call_criteria_dynamic<true> crit_bwd(rule.mw_indices_.indices());
1745 detail::after_handlers_call_helper<
1747 std::tuple_size<typename App::mw_container_t>::value - 1,
1748 typename App::context_t,
1749 typename App::mw_container_t>(crit_bwd, container, ctx, req, res);
1750 glob_completion_handler();
1753 rule.handle(req, res, rp);
1756 template<
typename App>
1757 typename std::enable_if<std::tuple_size<typename App::mw_container_t>::value == 0,
void>::type
1760 rule.handle(req, res, rp);
1765 for (
int i = 0; i < static_cast<int>(HTTPMethod::InternalMethodCount); i++)
1767 Trie& trie_ = per_methods_[i].trie;
1768 if (!trie_.is_empty())
1770 CROW_LOG_DEBUG << method_name(static_cast<HTTPMethod>(i));
1771 trie_.debug_print();
1776 std::vector<Blueprint*>& blueprints()
1783 return exception_handler_;
1786 static void default_exception_handler(response& res)
1789 res = response(500);
1795 catch (
const bad_request& e)
1797 res = response (400);
1798 res.body = e.what();
1800 catch (
const std::exception& e)
1802 CROW_LOG_ERROR <<
"An uncaught exception occurred: " << e.what();
1806 CROW_LOG_ERROR <<
"An uncaught exception occurred. The type was unknown so no information was available.";
1811 CatchallRule catchall_rule_;
1815 std::vector<BaseRule*> rules;
1822 std::array<PerMethod, static_cast<int>(HTTPMethod::InternalMethodCount)> per_methods_;
1823 std::vector<std::unique_ptr<BaseRule>> all_rules_;
1824 std::vector<Blueprint*> blueprints_;
1825 std::function<void(
crow::response&)> exception_handler_ = &default_exception_handler;