File indexing completed on 2025-09-17 08:24:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_HTTP_VECTOR_BODY_HPP
0011 #define BOOST_BEAST_HTTP_VECTOR_BODY_HPP
0012
0013 #include <boost/beast/http/vector_body_fwd.hpp>
0014
0015 #include <boost/beast/core/buffer_traits.hpp>
0016 #include <boost/beast/core/detail/clamp.hpp>
0017 #include <boost/beast/core/detail/config.hpp>
0018 #include <boost/beast/http/error.hpp>
0019 #include <boost/beast/http/message.hpp>
0020 #include <boost/asio/buffer.hpp>
0021 #include <boost/optional.hpp>
0022 #include <cstdint>
0023 #include <utility>
0024 #include <vector>
0025
0026 namespace boost {
0027 namespace beast {
0028 namespace http {
0029
0030
0031
0032
0033
0034
0035
0036 #if BOOST_BEAST_DOXYGEN
0037 template<class T, class Allocator = std::allocator<T>>
0038 #else
0039 template<class T, class Allocator>
0040 #endif
0041 struct vector_body
0042 {
0043 private:
0044 static_assert(sizeof(T) == 1,
0045 "T requirements not met");
0046
0047 public:
0048
0049
0050
0051
0052
0053 using value_type = std::vector<T, Allocator>;
0054
0055
0056
0057
0058
0059
0060
0061 static
0062 std::uint64_t
0063 size(value_type const& body)
0064 {
0065 return body.size();
0066 }
0067
0068
0069
0070
0071
0072 #if BOOST_BEAST_DOXYGEN
0073 using reader = __implementation_defined__;
0074 #else
0075 class reader
0076 {
0077 value_type& body_;
0078
0079 public:
0080 template<bool isRequest, class Fields>
0081 explicit
0082 reader(header<isRequest, Fields>&, value_type& b)
0083 : body_(b)
0084 {
0085 }
0086
0087 void
0088 init(boost::optional<
0089 std::uint64_t> const& length, error_code& ec)
0090 {
0091 if(length)
0092 {
0093 if(*length > body_.max_size())
0094 {
0095 BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
0096 return;
0097 }
0098 body_.reserve(beast::detail::clamp(*length));
0099 }
0100 ec = {};
0101 }
0102
0103 template<class ConstBufferSequence>
0104 std::size_t
0105 put(ConstBufferSequence const& buffers,
0106 error_code& ec)
0107 {
0108 auto const n = buffer_bytes(buffers);
0109 auto const len = body_.size();
0110 if (n > body_.max_size() - len)
0111 {
0112 BOOST_BEAST_ASSIGN_EC(ec, error::buffer_overflow);
0113 return 0;
0114 }
0115
0116 body_.resize(len + n);
0117 ec = {};
0118 return net::buffer_copy(net::buffer(
0119 &body_[0] + len, n), buffers);
0120 }
0121
0122 void
0123 finish(error_code& ec)
0124 {
0125 ec = {};
0126 }
0127 };
0128 #endif
0129
0130
0131
0132
0133
0134 #if BOOST_BEAST_DOXYGEN
0135 using writer = __implementation_defined__;
0136 #else
0137 class writer
0138 {
0139 value_type const& body_;
0140
0141 public:
0142 using const_buffers_type =
0143 net::const_buffer;
0144
0145 template<bool isRequest, class Fields>
0146 explicit
0147 writer(header<isRequest, Fields> const&, value_type const& b)
0148 : body_(b)
0149 {
0150 }
0151
0152 void
0153 init(error_code& ec)
0154 {
0155 ec = {};
0156 }
0157
0158 boost::optional<std::pair<const_buffers_type, bool>>
0159 get(error_code& ec)
0160 {
0161 ec = {};
0162 return {{const_buffers_type{
0163 body_.data(), body_.size()}, false}};
0164 }
0165 };
0166 #endif
0167 };
0168
0169 }
0170 }
0171 }
0172
0173 #endif