HTTPSClient.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. EQ2Emu: Everquest II Server Emulator
  3. Copyright (C) 2007-2025 EQ2Emu Development Team (https://www.eq2emu.com)
  4. This file is part of EQ2Emu.
  5. EQ2Emu is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emu is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emu. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef HTTPSCLIENT_H
  17. #define HTTPSCLIENT_H
  18. #include <boost/asio.hpp>
  19. #include <boost/beast.hpp>
  20. #include <boost/asio/ssl.hpp>
  21. #include <string>
  22. #include <unordered_map>
  23. namespace ssl = boost::asio::ssl;
  24. namespace asio = boost::asio;
  25. namespace beast = boost::beast;
  26. namespace http = beast::http;
  27. class HTTPSClient {
  28. public:
  29. HTTPSClient(const std::string& certFile, const std::string& keyFile);
  30. // Send a request with stored cookies and return response as string
  31. std::string sendRequest(const std::string& server, const std::string& port, const std::string& target);
  32. // Send a POST request with a JSON payload and return response as string
  33. std::string sendPostRequest(const std::string& server, const std::string& port, const std::string& target, const std::string& jsonPayload);
  34. std::string getServer() const { return server; }
  35. std::string getPort() const { return port; }
  36. private:
  37. std::unordered_map<std::string, std::string> cookies;
  38. std::string certFile;
  39. std::string keyFile;
  40. std::string server;
  41. std::string port;
  42. void parseAndStoreCookies(const http::response<http::string_body>& res);
  43. std::shared_ptr<boost::asio::ssl::context> createSSLContext(); // New helper function
  44. std::string buildCookieHeader() const;
  45. };
  46. #endif // HTTPSCLIENT_H