Line data Source code
1 : #ifndef OUT_CHUNK_HPP
2 : #define OUT_CHUNK_HPP
3 :
4 : #include <sstream>
5 : #include <iomanip>
6 : #include "out_data.hpp"
7 :
8 : namespace thinger::http::data{
9 :
10 : class out_chunk : public out_data{
11 :
12 : public:
13 10 : explicit out_chunk(const std::string& str) : str_(str){
14 10 : std::ostringstream ss;
15 10 : ss << std::hex << str_.size();
16 10 : size_ = ss.str();
17 10 : }
18 :
19 16 : out_chunk() : size_("0"){
20 8 : }
21 :
22 18 : ~out_chunk() override = default;
23 :
24 0 : size_t get_size() override{
25 0 : return str_.size();
26 : }
27 :
28 18 : void to_buffer(std::vector<boost::asio::const_buffer>& buffer) const override{
29 18 : static const std::string crlf = "\r\n";
30 18 : buffer.emplace_back(boost::asio::buffer(size_));
31 18 : buffer.emplace_back(boost::asio::buffer(crlf));
32 18 : buffer.emplace_back(boost::asio::buffer(str_));
33 18 : buffer.emplace_back(boost::asio::buffer(crlf));
34 18 : }
35 :
36 : private:
37 : std::string str_;
38 : std::string size_;
39 : };
40 :
41 : }
42 :
43 : #endif
|