Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
Read template_args from root in TOML preferences (#717).
Make max_workers work for httplib.
Fix implementation of str_icase_map for HTTP headers.
  • Loading branch information
tindy2013 committed Apr 3, 2024
1 parent 9e66b07 commit 0f2cefd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/handler/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)
{
std::string val = toml::format(value);
Expand Down
5 changes: 4 additions & 1 deletion src/server/webserver_httplib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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([&]()
Expand Down
9 changes: 7 additions & 2 deletions src/utils/map_extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@

#include <string>
#include <map>
#include <string.h>
#include <algorithm>

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);
});
}
};

Expand Down

0 comments on commit 0f2cefd

Please sign in to comment.