#include <kooling/http/http.h>
#include <kooling/http/http-detail.h>
#include <curl/curl.h>
#include <cstddef>
namespace kooling::http {
std::string url_encode(std::string_view data)
{
CURL *curl{ curl_easy_init() };
std::string result;
if (char *encoded{ curl_easy_escape(curl, data.data(), static_cast<int>(data.length())) })
{
result = encoded;
curl_free(encoded);
}
curl_easy_cleanup(curl);
return result;
}
namespace detail {
struct curl_global_holder
{
curl_global_holder()
{
curl_global_init(CURL_GLOBAL_NOTHING);
}
~curl_global_holder()
{
curl_global_cleanup();
}
};
void initialize_curl()<--- The function 'initialize_curl' is never used.
{
[[maybe_unused]] static curl_global_holder cgh{};
}
std::size_t write_callback(char* ptr, std::size_t, std::size_t nmemb, void *userdata)
{
std::string& s{ *static_cast<std::string*>(userdata) };
s.append(ptr, nmemb);
return nmemb;
}
} // namespace detail
} // namespace kooling::http