| 21 | { |
| 22 | public: |
| 23 | client(boost::asio::io_context& io_context, |
| 24 | const std::string& server, const std::string& path) |
| 25 | : resolver_(io_context), |
| 26 | socket_(io_context) |
| 27 | { |
| 28 | // Form the request. We specify the "Connection: close" header so that the |
| 29 | // server will close the socket after transmitting the response. This will |
| 30 | // allow us to treat all data up until the EOF as the content. |
| 31 | std::ostream request_stream(&request_); |
| 32 | request_stream << "GET " << path << " HTTP/1.0\r\n"; |
| 33 | request_stream << "Host: " << server << "\r\n"; |
| 34 | request_stream << "Accept: */*\r\n"; |
| 35 | request_stream << "Connection: close\r\n\r\n"; |
| 36 | |
| 37 | // Start an asynchronous resolve to translate the server and service names |
| 38 | // into a list of endpoints. |
| 39 | resolver_.async_resolve(server, "http", |
| 40 | std::bind(&client::handle_resolve, this, |
| 41 | boost::asio::placeholders::error, |
| 42 | boost::asio::placeholders::results)); |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | void handle_resolve(const boost::system::error_code& err, |
nothing calls this directly
no test coverage detected