mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
add GetOrCreateClient to http
This commit is contained in:
parent
defadf094f
commit
8b79049e7e
11
src/Http.cpp
11
src/Http.cpp
@ -10,10 +10,17 @@
|
||||
#include <random>
|
||||
#include <stdexcept>
|
||||
|
||||
// TODO: Add sentry error handling back
|
||||
|
||||
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) {
|
||||
httplib::SSLClient client(host, port);
|
||||
client.enable_server_certificate_verification(false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user