From 0f2cefd53787cee6377771788c80860640882557 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:09:21 +0800 Subject: [PATCH] Enhancements Read template_args from root in TOML preferences (#717). Make max_workers work for httplib. Fix implementation of str_icase_map for HTTP headers. --- src/handler/settings.cpp | 2 +- src/server/webserver_httplib.cpp | 5 ++++- src/utils/map_extra.h | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/handler/settings.cpp b/src/handler/settings.cpp index 655f5fdba..e41400c27 100644 --- a/src/handler/settings.cpp +++ b/src/handler/settings.cpp @@ -1167,7 +1167,7 @@ int loadExternalTOML(toml::value &root, ExternalConfig &ext) "exclude_remarks", ext.exclude ); - if(ext.tpl_args != nullptr) operate_toml_kv_table(toml::find_or>(section, "template_args", {}), "key", "value", + if(ext.tpl_args != nullptr) operate_toml_kv_table(toml::find_or>(root, "template_args", {}), "key", "value", [&](const toml::value &key, const toml::value &value) { std::string val = toml::format(value); diff --git a/src/server/webserver_httplib.cpp b/src/server/webserver_httplib.cpp index 2bf5590ad..6a7bfc159 100644 --- a/src/server/webserver_httplib.cpp +++ b/src/server/webserver_httplib.cpp @@ -187,7 +187,7 @@ int WebServer::start_web_server_multi(listener_args *args) { try { - std::rethrow_exception(e); + if (e) std::rethrow_exception(e); } catch (const httplib::Error &err) { @@ -212,6 +212,9 @@ int WebServer::start_web_server_multi(listener_args *args) { server.set_mount_point("/", serve_file_root); } + server.new_task_queue = [args] { + return new httplib::ThreadPool(args->max_workers); + }; server.bind_to_port(args->listen_address, args->port, 0); std::thread thread([&]() diff --git a/src/utils/map_extra.h b/src/utils/map_extra.h index 71af656f4..1fec977c8 100644 --- a/src/utils/map_extra.h +++ b/src/utils/map_extra.h @@ -3,13 +3,18 @@ #include #include -#include +#include struct strICaseComp { bool operator() (const std::string &lhs, const std::string &rhs) const { - return strcasecmp(lhs.c_str(), rhs.c_str()); + return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), + rhs.end(), + [](unsigned char c1, unsigned char c2) + { + return ::tolower(c1) < ::tolower(c2); + }); } };