http_response.hpp
1 #ifndef NOOS_CLOUD_HTTP_RESPONSE
2 #define NOOS_CLOUD_HTTP_RESPONSE
3 /*
4  * LICENSE HERE
5  */
6 #include <noos/cloud/asio/includes.ihh>
7 #include <boost/asio.hpp>
8 namespace noos {
10 namespace cloud {
11 typedef boost::system::error_code error_code;
12 
20 {
22  // to boost::system::error_code
23  error_code operator()(unsigned int status_code);
24 };
25 
39 {
40 public:
45  http_response(std::function<void(error_code error)> callback);
46 
48  http_response(std::string arg);
49 
54  unsigned int content_length();
55 
57  unsigned int strip_http_header(unsigned int bytes);
58 
60  std::string to_string();
61 
63  unsigned int bytes_received() const;
64 
69  bool check_http_header();
70 
72  bool consume_buffer(std::function<void(std::string)> callback,
73  unsigned int bytes);
74 
76  void flush_data();
77 
78 protected:
79  boost::asio::streambuf buffer_;
80  std::string reply_string;
81 private:
82  std::function<void(error_code error)> error_cb_;
83  unsigned int bytes_transferred_ = 0;
84  unsigned int content_length_ = 0;
85  std::atomic<bool> once_ = {false};
86 };
87 }
88 }
89 #endif
class for taking the body of the streambuf , in other case it will return an error ...
Definition: http_response.hpp:38
Definition: asio_handler.hpp:14
error_code operator()(unsigned int status_code)
operator which translates HTTP code errors
show the specific error due to a protocol error
Definition: http_response.hpp:19