| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HTTP_HTTP_CLIENT_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HTTP_HTTP_CLIENT_H_ |
| |
| #include <cstddef> |
| #include <memory> |
| #include <string> |
| #include <string_view> |
| |
| #include "absl/functional/any_invocable.h" |
| #include "absl/status/status.h" |
| #include "boost/asio.hpp" //NOLINT: boost::asio is commonly used in BMC |
| #include "boost/asio.hpp" // NOLINT: boost::asio is commonly used in BMC |
| #include "boost/asio/error.hpp" // NOLINT |
| #include "boost/asio/random_access_file.hpp" // NOLINT: boost::asio is commonly used in BMC |
| #include "boost/beast/core.hpp" // NOLINT: boost::beast is commonly used in BMC |
| #include "boost/beast/http.hpp" // NOLINT: boost::beast is commonly used in BMC |
| #include "boost/beast/version.hpp" // NOLINT: boost::beast is commonly used in BMC |
| #include "boost/filesystem.hpp" // NOLINT: boost::filesystem is commonly used in BMC |
| #include "boost/filesystem/operations.hpp" // NOLINT |
| #include "boost/system/detail/error_code.hpp" // NOLINT: boost::asio is commonly used in BMC |
| #include "tlbmc/http/http_client_interface.h" |
| |
| namespace milotic_tlbmc { |
| |
| class HttpClient : public HttpClientInterface, |
| public std::enable_shared_from_this<HttpClient> { |
| public: |
| explicit HttpClient(boost::asio::io_context& io_context) |
| : resolver_(boost::beast::net::make_strand(io_context)), |
| stream_(boost::beast::net::make_strand(io_context)) {} |
| ~HttpClient() override = default; |
| |
| bool IsActive() override; |
| absl::Status SendRequest( |
| boost::asio::io_context& io_context, std::string_view host, |
| std::string_view port, std::string_view target, |
| absl::AnyInvocable< |
| void(boost::beast::error_code, |
| boost::beast::http::response<boost::beast::http::string_body>)> |
| callback) override; |
| |
| void OnResolve(boost::beast::error_code ec, |
| boost::asio::ip::tcp::resolver::results_type results) override; |
| void OnConnect(boost::beast::error_code ec, |
| boost::asio::ip::tcp::resolver::results_type::endpoint_type |
| endpoint) override; |
| void OnWrite(boost::beast::error_code ec, |
| std::size_t bytes_transferred) override; |
| void OnRead(boost::beast::error_code ec, |
| std::size_t bytes_transferred) override; |
| |
| static std::unique_ptr<HttpClient> Create( |
| boost::asio::io_context& io_context) { |
| return std::make_unique<HttpClient>(io_context); |
| } |
| |
| protected: |
| // Networking objects |
| boost::asio::ip::tcp::resolver resolver_; |
| boost::beast::tcp_stream stream_; |
| boost::beast::flat_buffer buffer_; |
| |
| std::string host_; |
| std::string port_; |
| |
| bool is_active_ = false; |
| bool connection_established_ = false; |
| std::shared_ptr<ScanJob> job_; |
| }; |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HTTP_HTTP_CLIENT_H_ |