Implement vitastor-cli serve command to serve simple HTTP API

This commit is contained in:
Vitaliy Filippov
2026-04-27 15:24:44 +03:00
parent 6ca1b9eca9
commit 56a14cc0bd
9 changed files with 561 additions and 38 deletions
+34
View File
@@ -1,6 +1,7 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 or GNU GPL-2.0+ (see README.md for details)
#include "str_util.h"
#include "json_util.h"
std::map<std::string, std::string> json_to_string_map(const json11::Json::object & config)
@@ -49,3 +50,36 @@ std::string implode(const std::string & sep, json11::Json array)
}
return res;
}
static void json_array_add(json11::Json & to, json11::Json item)
{
if (to.is_null())
to = item;
else if (to.is_array())
{
auto a = to.array_items();
a.push_back(item);
to = a;
}
else
{
json11::Json::array a = {to};
a.push_back(item);
to = a;
}
}
json11::Json::object parse_uri_params(const std::string & params)
{
json11::Json::object obj;
auto list = explode("&", params, true);
for (auto & param: list)
{
auto pos = param.find("=");
if (pos != std::string::npos)
json_array_add(obj[urldecode(param.substr(0, pos))], urldecode(param.substr(pos+1)));
else
json_array_add(obj[urldecode(param)], true);
}
return obj;
}