-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTPClient.h
49 lines (36 loc) · 1.24 KB
/
HTTPClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef HTTPCLIENT_H
#define HTTPCLIENT_H
#include <boost/lexical_cast.hpp>
#include <boost/asio.hpp>
#include <boost/log/trivial.hpp>
#include <boost/bind.hpp>
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
class HTTPClient
{
public:
HTTPClient(boost::asio::io_service& service,
const std::string& remoteHost, unsigned int port);
virtual ~HTTPClient();
bool isOpen();
void closeConnection();
void sendRequest(const std::string& data);
boost::asio::streambuf& getBuffer();
protected:
private:
std::string remote_host_;
boost::asio::io_service io_service_;
boost::asio::ip::tcp::socket socket_;
boost::asio::streambuf response_;
boost::asio::streambuf content_response_;
void writeHandler(const boost::system::error_code& ec);
void readUntilHandler(const boost::system::error_code& ec);
void readStatusLineHandler(const boost::system::error_code& ec);
void readHeadersHandler(const boost::system::error_code& ec);
void readContentHandler(const boost::system::error_code& ec);
};
#endif // HTTPCLIENT_H