7 boost::asio::ip::tcp::resolver::query & query,
8 boost::asio::ip::tcp::resolver & resolver,
9 boost::asio::io_service & io_service
14 +
"Accept-Token: " +
token_ +
"\r\n"
15 +
"Connection: close\r\n"
16 +
"Content-Length: " + boost::lexical_cast<std::string>(
content_length)
21 timer_ = std::unique_ptr<boost::asio::deadline_timer>(
22 new boost::asio::deadline_timer(io_service));
33 ctx_.set_options(boost::asio::ssl::context::default_workarounds
34 |boost::asio::ssl::context::no_sslv2
35 |boost::asio::ssl::context::no_sslv3
36 |boost::asio::ssl::context::no_tlsv1
37 |boost::asio::ssl::context::single_dh_use);
41 ctx_.load_verify_file(
"ca.pem");
43 boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
45 tls_socket_->set_verify_mode(boost::asio::ssl::verify_peer
46 |boost::asio::ssl::verify_fail_if_no_peer_cert);
51 boost::asio::async_connect(
tls_socket_->lowest_layer(),
55 boost::asio::placeholders::error));
61 char subject_name[256];
62 X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle());
63 X509_NAME_oneline(X509_get_subject_name(cert), subject_name, 256);
72 timer_->expires_from_now(boost::posix_time::seconds(30));
73 tls_socket_->async_handshake(boost::asio::ssl::stream_base::client,
76 boost::asio::placeholders::error));
79 std::cerr <<
"connect failed: " << error.message() <<
"\n";
89 std::ostream request_stream(&
request_);
91 timer_->expires_from_now(boost::posix_time::seconds(30));
97 boost::asio::placeholders::error));
100 std::cerr <<
"Handshake failed: " << error.message() <<
"\n";
109 timer_->expires_from_now(boost::posix_time::seconds(30));
116 boost::asio::placeholders::error));
129 std::istream response_stream(&
response_);
130 std::string http_version;
131 response_stream >> http_version;
132 unsigned int status_code;
133 response_stream >> status_code;
134 std::string status_message;
135 std::getline( response_stream, status_message );
136 if (!response_stream || http_version.substr(0, 5) !=
"HTTP/") {
140 if (status_code != 200) {
144 timer_->expires_from_now(boost::posix_time::seconds(30));
152 boost::asio::placeholders::error));
164 timer_->expires_from_now(boost::posix_time::seconds(30));
171 boost::asio::placeholders::error));
183 timer_->expires_from_now(boost::posix_time::seconds(30));
187 boost::asio::transfer_at_least(1),
190 boost::asio::placeholders::error));
193 std::string json((std::istreambuf_iterator<char>(&
response_)),
194 std::istreambuf_iterator<char>());
198 else if (err != boost::asio::error::eof) {
213 timer_->expires_at(boost::posix_time::pos_infin);
219 if (
timer_->expires_at() <= boost::asio::deadline_timer::traits_type::now()) {
220 std::cerr <<
"connection time-out" << std::endl;
std::unique_ptr< boost_tls_socket > tls_socket_
tls/ssl socket wrapper
std::string header_
Header that will be used.
void handle_connect(const boost::system::error_code &error)
begin connect
void invalid_request(const std::string message)
Handle Invalid Query - e.g.: response which states our query was invalid.
std::size_t content_length_
Content-Length.
boost::asio::ssl::context ctx_
tls context
bool verify_certificate(bool preverified, boost::asio::ssl::verify_context &ctx)
verify TLS certificate
void content_length(std::string response, std::size_t &length)
get the content leangth from
std::string post_
Actual post Data.
void handle_read_headers(const boost::system::error_code &err)
Callback for Handling Headers.
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > boost_tls_socket
boost tls wraps around a tcp socket
std::atomic< bool > flag_
flag used to extract header
boost::asio::streambuf response_
Response Container.
boost::asio::streambuf request_
Request Container.
void handle_write(const boost::system::error_code &err)
Callback for handling request and waiting for response.
void error_handler(const boost::system::error_code &error)
Handle an Error.
void reset()
reset handler (clear data, bytes, etc) and stop connection
void check_timeout()
check timed-out
std::string json_
JSON reply.
const std::string token_
user authentication token
void handle_read_status_line(const boost::system::error_code &err)
Callback for handling HTTP Header Response Data.
void handle_handshake(const boost::system::error_code &error)
handle handshake
void schedule(boost::asio::ip::tcp::resolver::query &query, boost::asio::ip::tcp::resolver &resolver, boost::asio::io_service &io_service)
void handle_read_content(const boost::system::error_code &err)
Callback for Handling Actual Data Contents.
std::size_t bytes_transferred_
Bytes Transferred.
std::unique_ptr< boost::asio::deadline_timer > timer_
time-out timer
constexpr char address[]
api.rapp.cloud -