add GetOrCreateClient to http

This commit is contained in:
Lion 2023-12-22 13:09:40 +01:00 committed by GitHub
parent defadf094f
commit 8b79049e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,10 +10,17 @@
#include <random> #include <random>
#include <stdexcept> #include <stdexcept>
// TODO: Add sentry error handling back
using json = nlohmann::json; using json = nlohmann::json;
static std::shared_ptr<httplib::SSLClient> GetOrCreateClient(const std::string& host, int port) {
static thread_local std::unordered_map<std::pair<std::string, int>, std::shared_ptr<httplib::SSLClient>> clients {};
const auto idx = std::pair<std::string, int>(host, port);
if (!clients.contains(idx)) {
clients.emplace(std::make_shared<httplib::SSLClient>(host, port));
}
clients.at(idx);
}
std::string Http::GET(const std::string& host, int port, const std::string& target, unsigned int* status) { std::string Http::GET(const std::string& host, int port, const std::string& target, unsigned int* status) {
httplib::SSLClient client(host, port); httplib::SSLClient client(host, port);
client.enable_server_certificate_verification(false); client.enable_server_certificate_verification(false);