RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
asio_handler.hpp
Go to the documentation of this file.
1 #ifndef RAPP_ASIO_HANDLER
2 #define RAPP_ASIO_HANDLER
3 #include "includes.ihh"
4 namespace rapp {
5 namespace cloud {
15 {
16 public:
17 
19  asio_handler(const std::string token)
20  : token_(token)
21  {}
22 
24  void error_handler(const boost::system::error_code & error);
25 
27  void invalid_request(const std::string message);
28 
30  void content_length(std::string response, std::size_t& length);
31 
33  bool has_content_length(std::string response);
34 
36  std::string strip_header(std::string response);
37 
39  std::string random_boundary() const;
40 
43  std::string escape_string(const std::string & str);
44 
47  std::string decode64(const std::string &val);
48 
52  std::string encode64(const std::string &val);
53 
54 protected:
55 
57  std::string header_;
59  std::string post_;
61  std::function<void(std::string)> callback_;
63  boost::asio::streambuf request_;
65  boost::asio::streambuf response_;
66 
68  std::unique_ptr<boost::asio::deadline_timer> timer_;
70  std::atomic<bool> flag_ = {false};
72  std::size_t content_length_ = 0;
74  std::size_t bytes_transferred_ = 0;
76  std::string json_;
78  const std::string token_;
79 };
80 }
81 }
82 #endif
std::string header_
Header that will be used.
base class for asio handling, including helper methods and most protected members ...
void invalid_request(const std::string message)
Handle Invalid Query - e.g.: response which states our query was invalid.
std::string random_boundary() const
Create a random boundary for the multipart/form in HTTP.
std::size_t content_length_
Content-Length.
std::string escape_string(const std::string &str)
escape JSON strings when sending them over the socket
std::string decode64(const std::string &val)
decode base64
std::string encode64(const std::string &val)
encode base64
void content_length(std::string response, std::size_t &length)
get the content leangth from
std::string post_
Actual post Data.
bool has_content_length(std::string response)
examine if the header response contains a content-length filed
std::atomic< bool > flag_
flag used to extract header
asio_handler(const std::string token)
ctor
boost::asio::streambuf response_
Response Container.
std::string strip_header(std::string response)
remove/strip the HTTP header and
boost::asio::streambuf request_
Request Container.
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
void error_handler(const boost::system::error_code &error)
Handle an Error.
Definition: asio_handler.cpp:6
std::string json_
JSON reply.
const std::string token_
user authentication token
std::size_t bytes_transferred_
Bytes Transferred.
std::unique_ptr< boost::asio::deadline_timer > timer_
time-out timer