asio_handler.hpp
1 #ifndef NOOS_ASIO_HANDLER
2 #define NOOS_ASIO_HANDLER
3 /*
4  * LICENSE HERE
5  */
6 #include "includes.ihh"
7 #include <boost/asio/ssl.hpp>
8 #include <noos/cloud/asio/http_response.hpp>
9 typedef boost::asio::ip::tcp::socket http_socket;
10 typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> tls_socket;
11 typedef boost::system::error_code error_code;
12 typedef boost::asio::ip::tcp::resolver resolver;
13 
14 namespace noos {
16 namespace cloud {
25 template <class socket_type,
26  class child_class>
28 : protected http_response
29 {
30 public:
37  asio_handler(const bool keep_alive,
38  std::function<void(error_code)> error_callback);
39 
41  void set_socket(const std::shared_ptr<socket_type> socket);
42 
47  void write_request(const boost::system::error_code & err,
48  const std::size_t bytes);
49 
54  void read_status_line(const boost::system::error_code & err,
55  const std::size_t bytes);
56 
61  void read_headers(const boost::system::error_code & err,
62  const std::size_t bytes);
63 
68  void read_content(
69  const boost::system::error_code & err,
70  const std::size_t bytes
71  );
72 
77  void end(const boost::system::error_code & err);
78 
79 protected:
80  std::shared_ptr<socket_type> socket_;
81  bool keep_alive_ = false;
82 };
83 }
84 }
85 #include "asio_handler.tpl"
86 #endif
void read_content(const boost::system::error_code &err, const std::size_t bytes)
strip the header and read the POST data
void write_request(const boost::system::error_code &err, const std::size_t bytes)
write the cloud request to the socket
void set_socket(const std::shared_ptr< socket_type > socket)
set socket pointer
void read_headers(const boost::system::error_code &err, const std::size_t bytes)
read HTTP headers and validate
class for taking the body of the streambuf , in other case it will return an error ...
Definition: http_response.hpp:38
ASIO socket controller of boost asio socket type T.
Definition: asio_handler.hpp:27
Definition: asio_handler.hpp:14
void end(const boost::system::error_code &err)
close socket and cleanup members
asio_handler(const bool keep_alive, std::function< void(error_code)> error_callback)
construct by callbacks and socket T pointer
void read_status_line(const boost::system::error_code &err, const std::size_t bytes)
read first HTTP line and check for a 200 response