|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <boost/asio.hpp> |
| 4 | +#include <boost/beast.hpp> |
| 5 | + |
| 6 | +#include <functional> |
| 7 | +#include <optional> |
| 8 | +#include <string> |
| 9 | + |
| 10 | +namespace http_client |
| 11 | +{ |
| 12 | + struct HttpRequestParams |
| 13 | + { |
| 14 | + boost::beast::http::verb method; |
| 15 | + std::string host; |
| 16 | + std::string port; |
| 17 | + std::string endpoint; |
| 18 | + std::string token; |
| 19 | + std::string user_pass; |
| 20 | + std::string body; |
| 21 | + |
| 22 | + HttpRequestParams(boost::beast::http::verb method, |
| 23 | + const std::string& host, |
| 24 | + const std::string& port, |
| 25 | + const std::string& endpoint, |
| 26 | + const std::string& token = "", |
| 27 | + const std::string& user_pass = "", |
| 28 | + const std::string& body = "") |
| 29 | + : method(method) |
| 30 | + , host(host) |
| 31 | + , port(port) |
| 32 | + , endpoint(endpoint) |
| 33 | + , token(token) |
| 34 | + , user_pass(user_pass) |
| 35 | + , body(body) |
| 36 | + { |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + boost::beast::http::request<boost::beast::http::string_body> CreateHttpRequest(const HttpRequestParams& params); |
| 41 | + |
| 42 | + boost::asio::awaitable<void> |
| 43 | + Co_PerformHttpRequest(boost::asio::ip::tcp::socket& socket, |
| 44 | + boost::beast::http::request<boost::beast::http::string_body>& req, |
| 45 | + boost::beast::error_code& ec, |
| 46 | + std::function<void()> onUnauthorized, |
| 47 | + std::function<void(const std::string&)> onSuccess = {}); |
| 48 | + |
| 49 | + boost::asio::awaitable<void> Co_MessageProcessingTask(const std::string& token, |
| 50 | + HttpRequestParams params, |
| 51 | + std::function<std::string()> messageGetter, |
| 52 | + std::function<void()> onUnauthorized, |
| 53 | + std::function<void(const std::string&)> onSuccess = {}); |
| 54 | + |
| 55 | + boost::beast::http::response<boost::beast::http::dynamic_body> PerformHttpRequest(const HttpRequestParams& params); |
| 56 | + |
| 57 | + std::optional<std::string> |
| 58 | + AuthenticateWithUuid(const std::string& host, const std::string& port, const std::string& uuid); |
| 59 | + std::optional<std::string> AuthenticateWithUserPassword(const std::string& host, |
| 60 | + const std::string& port, |
| 61 | + const std::string& user, |
| 62 | + const std::string& password); |
| 63 | +} // namespace http_client |
0 commit comments