mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-25 21:40:09 +00:00
add GetOrCreateClient to http
This commit is contained in:
1 file changed
+9
-2
+9
-2
@@ -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);
|
||||||
|
|||||||
Reference in new issue
Block a user