37 tcp::resolver resolver_;
39 boost::beast::flat_buffer buffer_;
40 http::request<http::empty_body> req_;
41 http::response<http::string_body> res_;
55 const std::string& etpServerHost,
56 uint16_t etpServerPort,
57 const std::string& etpServerTarget,
59 const std::string& etpServerAuthorization =
"",
60 const std::string& proxyHost =
"",
61 uint16_t proxyPort = 80,
62 const std::string& proxyAuthorization =
"")
65 req_.version(version);
66 req_.method(http::verb::get);
67 req_.target(etpServerTarget);
68 req_.set(http::field::host, etpServerHost +
':' + std::to_string(etpServerPort));
69 req_.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
70 if (!etpServerAuthorization.empty()) {
71 req_.set(http::field::authorization, etpServerAuthorization);
73 if (!proxyAuthorization.empty()) {
74 req_.set(http::field::proxy_authorization, proxyAuthorization);
78 resolver_.async_resolve(
79 proxyHost.empty() ? etpServerHost : proxyHost,
80 std::to_string(proxyHost.empty() ? etpServerPort : proxyPort),
82 &HttpClientSession::on_resolve,
84 std::placeholders::_1,
85 std::placeholders::_2));
90 boost::system::error_code ec,
91 tcp::resolver::results_type results)
94 std::cerr <<
"resolve : " << ec.message() << std::endl;
99 boost::asio::async_connect(
104 &HttpClientSession::on_connect,
106 std::placeholders::_1));
110 on_connect(boost::system::error_code ec)
113 std::cerr <<
"connect : " << ec.message() << std::endl;
118 http::async_write(socket_, req_,
120 &HttpClientSession::on_write,
122 std::placeholders::_1,
123 std::placeholders::_2));
128 boost::system::error_code ec,
129 std::size_t bytes_transferred)
131 boost::ignore_unused(bytes_transferred);
134 std::cerr <<
"write : " << ec.message() << std::endl;
139 http::async_read(socket_, buffer_, res_,
141 &HttpClientSession::on_read,
143 std::placeholders::_1,
144 std::placeholders::_2));
149 boost::system::error_code ec,
150 std::size_t bytes_transferred)
152 boost::ignore_unused(bytes_transferred);
155 std::cerr <<
"read : " << ec.message() << std::endl;
160 socket_.shutdown(tcp::socket::shutdown_both, ec);
163 if (ec && ec != boost::system::errc::not_connected) {
164 std::cerr <<
"shutdown : " << ec.message() << std::endl;
171 const http::response<http::string_body>& getResponse()
const {