diff --git a/source/WorldServer/Web/HTTPSClient.cpp b/source/WorldServer/Web/HTTPSClient.cpp index 6627447..b68d6d4 100644 --- a/source/WorldServer/Web/HTTPSClient.cpp +++ b/source/WorldServer/Web/HTTPSClient.cpp @@ -87,7 +87,10 @@ std::string base64_encode(const std::string& input) { } HTTPSClient::HTTPSClient(const std::string& certFile, const std::string& keyFile) - : certFile(certFile), keyFile(keyFile) {} + : certFile(certFile), keyFile(keyFile) { + // SSL and TCP setup + sslCtx = createSSLContext(); + } std::shared_ptr HTTPSClient::createSSLContext() { auto sslCtx = std::make_shared(boost::asio::ssl::context::tlsv13_client); @@ -128,8 +131,6 @@ std::string HTTPSClient::sendRequest(const std::string& server, const std::strin try { boost::asio::io_context ioContext; - // SSL and TCP setup - auto sslCtx = createSSLContext(); auto stream = std::make_shared>(ioContext, *sslCtx); auto resolver = std::make_shared(ioContext); auto results = resolver->resolve(server, port); @@ -258,11 +259,11 @@ std::string HTTPSClient::sendRequest(const std::string& server, const std::strin // Store cookies from the response if (res->base().count(http::field::set_cookie) > 0) { auto set_cookie_value = res->base()[http::field::set_cookie].to_string(); - std::istringstream stream(set_cookie_value); + std::istringstream streamdata(set_cookie_value); std::string token; // Parse "Set-Cookie" field for name-value pairs - while (std::getline(stream, token, ';')) { + while (std::getline(streamdata, token, ';')) { auto pos = token.find('='); if (pos != std::string::npos) { std::string name = token.substr(0, pos); @@ -290,7 +291,6 @@ std::string HTTPSClient::sendPostRequest(const std::string& server, const std::s boost::asio::io_context ioContext; // SSL and TCP setup - auto sslCtx = createSSLContext(); auto stream = std::make_shared>(ioContext, *sslCtx); auto resolver = std::make_shared(ioContext); auto results = resolver->resolve(server, port); diff --git a/source/WorldServer/Web/HTTPSClient.h b/source/WorldServer/Web/HTTPSClient.h index 75690f1..a5b05ff 100644 --- a/source/WorldServer/Web/HTTPSClient.h +++ b/source/WorldServer/Web/HTTPSClient.h @@ -47,7 +47,8 @@ public: private: std::unordered_map cookies; - + std::shared_ptr sslCtx; + std::string certFile; std::string keyFile; std::string server;