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.
This commit is contained in:
Tindy X 2024-04-03 17:09:21 +08:00
parent 9e66b07251
commit 0f2cefd537
No known key found for this signature in database
GPG Key ID: 7FA1E66774759718
3 changed files with 12 additions and 4 deletions

View File

@ -1167,7 +1167,7 @@ int loadExternalTOML(toml::value &root, ExternalConfig &ext)
"exclude_remarks", ext.exclude "exclude_remarks", ext.exclude
); );
if(ext.tpl_args != nullptr) operate_toml_kv_table(toml::find_or<std::vector<toml::table>>(section, "template_args", {}), "key", "value", if(ext.tpl_args != nullptr) operate_toml_kv_table(toml::find_or<std::vector<toml::table>>(root, "template_args", {}), "key", "value",
[&](const toml::value &key, const toml::value &value) [&](const toml::value &key, const toml::value &value)
{ {
std::string val = toml::format(value); std::string val = toml::format(value);

View File

@ -187,7 +187,7 @@ int WebServer::start_web_server_multi(listener_args *args)
{ {
try try
{ {
std::rethrow_exception(e); if (e) std::rethrow_exception(e);
} }
catch (const httplib::Error &err) 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.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); server.bind_to_port(args->listen_address, args->port, 0);
std::thread thread([&]() std::thread thread([&]()

View File

@ -3,13 +3,18 @@
#include <string> #include <string>
#include <map> #include <map>
#include <string.h> #include <algorithm>
struct strICaseComp struct strICaseComp
{ {
bool operator() (const std::string &lhs, const std::string &rhs) const 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);
});
} }
}; };